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