001/*
002 *                    BioJava development code
003 *
004 * This code may be freely distributed and modified under the
005 * terms of the GNU Lesser General Public Licence.  This should
006 * be distributed with the code.  If you do not have a copy,
007 * see:
008 *
009 *      http://www.gnu.org/copyleft/lesser.html
010 *
011 * Copyright for this code is held jointly by the individual
012 * authors.  These should be listed in @author doc comments.
013 *
014 * For more information on the BioJava project and its aims,
015 * or to join the biojava-l mailing list, visit the home page
016 * at:
017 *
018 *      http://www.biojava.org/
019 *
020 * Created on 05.03.2004
021 * @author Andreas Prlic
022 *
023 */
024package org.biojava.nbio.structure;
025import java.io.Serializable;
026
027
028
029/**
030 * A nucleotide group is almost the same as a Hetatm group.
031 * @see HetatomImpl
032 * @see AminoAcidImpl
033 * @author Andreas Prlic
034 * @since 1.4
035 * @version %I% %G%
036 */
037public class NucleotideImpl extends HetatomImpl implements Group, Serializable, Cloneable {
038
039        private static final long serialVersionUID = -7467726932980288712L;
040        /** this is a "nucleotide", a special occurance of a Hetatom. */
041        public static final GroupType type = GroupType.NUCLEOTIDE;
042
043        /*
044         * inherits most from Hetero and has just a few extensions.
045         */
046        public NucleotideImpl() {
047                super();
048
049        }
050
051        @Override
052        public GroupType getType(){ return type;}
053
054
055        @Override
056        public String toString(){
057
058                String str = "PDB: "+ pdb_name + " " + residueNumber +  " "+ pdb_flag;
059                if (pdb_flag) {
060                        str = str + "atoms: "+atoms.size();
061                }
062                return str ;
063
064        }
065
066        /**
067         * Returns the O3' atom if present, otherwise null
068         * @return O3' atom or null
069         */
070        public Atom getO3Prime() {
071
072                return getAtom("O3'");
073
074        }
075
076        /**
077         * Returns the O5' atom if present, otherwise null
078         * @return O5' atom or null
079         */
080        public Atom getO5Prime() {
081
082                return getAtom("O5'");
083
084        }
085
086        /**
087         * Returns the P atom if present, otherwise null
088         * @return P atom or null
089         */
090        public Atom getP() {
091
092                return getAtom("P");
093
094        }
095
096        // note we need to implement a clone here, despite there's one in super class already,
097        // that's due to issue https://github.com/biojava/biojava/issues/631 - JD 2017-01-21
098        @Override
099        public Object clone() {
100
101                NucleotideImpl n = new NucleotideImpl();
102                n.setPDBFlag(has3D());
103                n.setResidueNumber(getResidueNumber());
104
105                n.setPDBName(getPDBName());
106
107                // copy the atoms
108                for (Atom atom1 : atoms) {
109                        Atom atom = (Atom) atom1.clone();
110                        n.addAtom(atom);
111                        atom.setGroup(n);
112                }
113
114                // copying the alt loc groups if present, otherwise they stay null
115                if (getAltLocs()!=null && !getAltLocs().isEmpty()) {
116                        for (Group altLocGroup:this.getAltLocs()) {
117                                Group nAltLocGroup = (Group)altLocGroup.clone();
118                                n.addAltLoc(nAltLocGroup);
119                        }
120                }
121                
122                if (chemComp!=null)
123                        n.setChemComp(chemComp);
124
125
126                return n;
127        }
128}