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;
025
026/**
027 * AminoAcid inherits most from Hetatom.  Adds a few AminoAcid
028 * specific methods.
029 * @author Andreas Prlic
030 * @author Jules Jacobsen
031 * @since 1.4
032 * @version %I% %G%
033 *
034 */
035public class AminoAcidImpl extends HetatomImpl implements AminoAcid {
036
037        private static final long serialVersionUID = -6018854413829044230L;
038
039        /** this is an Amino acid. type is "amino". */
040        public static final GroupType type = GroupType.AMINOACID;
041
042        /**
043         * IUPAC amino acid residue names
044         */
045        private Character amino_char ;
046
047        private String recordType; // allows to distinguish between AAs that have been created from SEQRES records and ATOM records
048
049        /**
050         * inherits most from Hetero and has just a few extensions.
051         */
052        public AminoAcidImpl() {
053                super();
054
055                amino_char = null;
056                recordType = ATOMRECORD;
057        }
058
059        @Override
060        public GroupType getType(){ return type;}
061
062        /**
063         * {@inheritDoc}
064         */
065        @Override
066        public Atom getN()    {return getAtom("N");  }
067
068        /**
069         * {@inheritDoc}
070         */
071        @Override
072        public Atom getCA()   {
073                // note CA can also be Calcium, but that can't happen in a standard aminoacid, so this should be safe
074                return getAtom("CA");
075        }
076
077        /**
078         * {@inheritDoc}
079         */
080        @Override
081        public Atom getC()    {return getAtom("C");  }
082
083        /**
084         * {@inheritDoc}
085         */
086        @Override
087        public Atom getO()    {return getAtom("O");  }
088
089        /**
090         * {@inheritDoc}
091         */
092        @Override
093        public Atom getCB()   {return getAtom("CB"); }
094
095
096        /**
097         * {@inheritDoc}
098         */
099        @Override
100        public  Character getAminoType() {
101                return amino_char;
102        }
103
104        /**
105         * {@inheritDoc}
106         */
107        @Override
108        public void setAminoType(Character aa){
109                amino_char  = aa ;
110        }
111
112        /**
113         * {@inheritDoc}
114         */
115        @Override
116        public void setRecordType(String recordName) {
117                recordType = recordName;
118        }
119
120        /**
121         * {@inheritDoc}
122         */
123        @Override
124        public String getRecordType() {
125                return recordType;
126        }
127
128        /** string representation. */
129        @Override
130        public String toString(){
131
132                String str = "AminoAcid "+ recordType + ":"+ pdb_name + " " + amino_char +
133                                " " + residueNumber +  " "+ pdb_flag + " " + recordType  ;
134                if (pdb_flag) {
135                        str = str + " atoms: "+atoms.size();
136                }
137                if (!getAltLocs().isEmpty())
138                        str += " has altLocs :" + getAltLocs().size();
139
140                return str ;
141
142        }
143        /** set three character name of AminoAcid.
144         *
145         * @param s  a String specifying the PDBName value
146         * @see #getPDBName()
147         */
148        @Override
149        public void setPDBName(String s) {
150
151                pdb_name =s ;
152
153        }
154
155
156        /** returns and identical copy of this Group object .
157         * @return  and identical copy of this Group object
158         */
159        @Override
160        public Object clone() {
161
162                AminoAcidImpl n = new AminoAcidImpl();
163                n.setPDBFlag(has3D());
164                n.setResidueNumber(getResidueNumber());
165
166                n.setPDBName(getPDBName());
167
168                n.setAminoType(getAminoType());
169                n.setRecordType(recordType);
170
171                //clone atoms and bonds.
172                cloneAtomsAndBonds(n);
173
174                // copying the alt loc groups if present, otherwise they stay null
175                if (getAltLocs()!=null && !getAltLocs().isEmpty()) {
176                        for (Group altLocGroup:this.getAltLocs()) {
177                                Group nAltLocGroup = (Group)altLocGroup.clone();
178                                n.addAltLoc(nAltLocGroup);
179                        }
180                }
181
182                if (chemComp!=null)
183                        n.setChemComp(chemComp);
184
185
186                return n;
187        }
188
189
190}