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 Jul 25, 2006
021 *
022 */
023package org.biojava.nbio.structure.align.gui.jmol;
024
025import java.util.regex.Matcher;
026import java.util.regex.Pattern;
027
028
029/** This class uniquely describes an atom
030 *
031 * @author Andreas Prlic
032 *
033 */
034public class AtomInfo {
035
036        String chainId;
037        String atomName;
038
039        String residueName;
040        String residueNumber;
041        int modelNumber;
042
043        private static Pattern inscodePatter ;
044        static {
045                inscodePatter = Pattern.compile("([0-9]+)([a-zA-Z]*)?");
046        }
047
048        public AtomInfo() {
049                super();
050
051        }
052
053        public static AtomInfo fromString(String atomInfo){
054                return AtomInfoParser.parse(atomInfo);
055        }
056
057        public int getModelNumber() {
058                return modelNumber;
059        }
060
061        public void setModelNumber(int modelNumber) {
062                this.modelNumber = modelNumber;
063        }
064
065        public String getResidueName() {
066                return residueName;
067        }
068
069        /** Including insertion code
070         *
071         * @param residueName
072         */
073        public void setResidueName(String residueName) {
074                this.residueName = residueName;
075        }
076
077        public String getResidueNumber() {
078                return residueNumber;
079        }
080
081        public void setResidueNumber(String residueNumber) {
082                this.residueNumber = residueNumber;
083        }
084
085        public String getChainId() {
086                return chainId;
087        }
088
089
090
091        public void setChainId(String chainId) {
092                this.chainId = chainId;
093        }
094
095
096
097        public String getAtomName() {
098                return atomName;
099        }
100
101
102
103        public void setAtomName(String name) {
104                this.atomName = name;
105        }
106
107        @Override
108        public String toString() {
109                String aa3 = "";
110                boolean printResName = true;
111
112                String chain1 ="";
113                String res1 = "";
114
115                aa3 = residueName;
116                res1 = residueNumber;
117                chain1 = chainId;
118
119                StringBuffer buf = new StringBuffer();
120                if ( printResName) {
121                        if ( !aa3.equals("")){
122                                buf.append("[");
123                                buf.append(aa3);
124                                buf.append("]");
125                        }
126                }
127                if ( ! res1.equals("")) {
128
129                        // let's check if there is an insertion code...
130                        Matcher matcher = inscodePatter.matcher(res1);
131
132                        boolean found = matcher.find();
133                        if ( ! found) {
134                                System.err.println("JmolTools: could not parse the residue number string " + res1);
135                                buf.append(res1);
136                        } else {
137                                String residueNumber = matcher.group(1);
138                                String insCode = matcher.group(2);
139                                buf.append(residueNumber);
140                                if ( insCode != null && ! ( insCode.equals(""))) {
141                                        buf.append("^");
142                                        buf.append(insCode);
143                                }
144                        }
145
146                }
147
148                if ( ! chain1.equals("")){
149                        buf.append(":");
150                        buf.append(chain1);
151                }
152
153                if ( atomName != null) {
154                        buf.append(".");
155                        buf.append(atomName);
156                }
157                if ( modelNumber > 0) {
158                        buf.append("/");
159                        buf.append(modelNumber);
160                }
161                return buf.toString();
162        }
163
164
165
166
167}