1
/* $Revision: 8130 $ $Author: egonw $ $Date: 2007-03-16 15:15:22 +0100 (Fri, 16 Mar 2007) $
3
* Copyright (C) 2005-2007 Martin Eklund <martin.eklund@farmbio.uu.se>
5
* Contact: cdk-devel@lists.sourceforge.net
7
* This program is free software; you can redistribute it and/or
8
* modify it under the terms of the GNU Lesser General Public License
9
* as published by the Free Software Foundation; either version 2.1
10
* of the License, or (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public License
18
* along with this program; if not, write to the Free Software
19
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21
package org.openscience.cdk.templates;
23
import java.util.Enumeration;
24
import java.util.HashMap;
25
import java.util.Iterator;
26
import java.util.List;
28
import org.openscience.cdk.AminoAcid;
29
import org.openscience.cdk.dict.DictRef;
30
import org.openscience.cdk.interfaces.IAtom;
31
import org.openscience.cdk.interfaces.IAtomContainer;
32
import org.openscience.cdk.interfaces.IBond;
33
import org.openscience.cdk.interfaces.IChemFile;
34
import org.openscience.cdk.io.CMLReader;
35
import org.openscience.cdk.tools.LoggingTool;
36
import org.openscience.cdk.tools.manipulator.AminoAcidManipulator;
37
import org.openscience.cdk.tools.manipulator.ChemFileManipulator;
40
* Tool that provides templates for the (natural) amino acids.
42
* @author Martin Eklund <martin.eklund@farmbio.uu.se>
44
* @cdk.keyword templates
45
* @cdk.keyword amino acids, stuctures
46
* @cdk.created 2005-02-08
48
public class AminoAcids {
50
private static final LoggingTool logger = new LoggingTool(AminoAcids.class);
53
* Creates matrix with info about the bonds in the amino acids.
54
* 0 = bond id, 1 = atom1 in bond, 2 = atom2 in bond, 3 = bond order.
57
public static int[][] aaBondInfo() {
59
if (aminoAcids == null) {
63
int[][] info = new int[153][4];
67
for (int aa=0; aa<aminoAcids.length; aa++) {
68
AminoAcid acid = aminoAcids[aa];
70
logger.debug("#bonds for ", acid.getProperty(RESIDUE_NAME).toString(), " = " + acid.getBondCount());
71
total += acid.getBondCount();
72
logger.debug("total #bonds: ", total);
74
Iterator bonds = acid.bonds();
75
while (bonds.hasNext()) {
76
IBond bond = (IBond) bonds.next();
77
info[counter][0] = counter;
78
info[counter][1] = acid.getAtomNumber(bond.getAtom(0));
79
info[counter][2] = acid.getAtomNumber(bond.getAtom(1));
80
info[counter][3] = (int)bond.getOrder();
86
logger.error("Error while creating AA info! Bond count is too large: ", counter);
93
private static AminoAcid[] aminoAcids = null;
95
public final static String RESIDUE_NAME = "residueName";
96
public final static String RESIDUE_NAME_SHORT = "residueNameShort";
97
public final static String NO_ATOMS = "noOfAtoms";
98
public final static String NO_BONDS = "noOfBonds";
99
public final static String ID = "id";
102
* Creates amino acid AminoAcid objects.
104
* @return aminoAcids, a HashMap containing the amino acids as AminoAcids.
106
public static AminoAcid[] createAAs() {
107
if (aminoAcids != null) {
111
// Create set of AtomContainers
112
aminoAcids = new AminoAcid[20];
114
IChemFile list = new org.openscience.cdk.ChemFile();
115
CMLReader reader = new CMLReader(
116
AminoAcids.class.getClassLoader().getResourceAsStream(
117
"data/templates/list_aminoacids.cml"
121
list = (IChemFile)reader.read(list);
122
List containersList = ChemFileManipulator.getAllAtomContainers(list);
123
Iterator iterator = containersList.iterator();
125
while(iterator.hasNext())
127
IAtomContainer ac = (IAtomContainer)iterator.next();
128
logger.debug("Adding AA: ", ac);
129
// convert into an AminoAcid
130
AminoAcid aminoAcid = new AminoAcid();
131
java.util.Iterator atoms = ac.atoms();
132
Enumeration props = ac.getProperties().keys();
133
while (props.hasMoreElements()) {
134
Object next = props.nextElement();
135
logger.debug("Prop class: " + next.getClass().getName());
136
logger.debug("Prop: " + next.toString());
137
if (next instanceof DictRef) {
138
DictRef dictRef = (DictRef)next;
139
// logger.debug("DictRef type: " + dictRef.getType());
140
if (dictRef.getType().equals("pdb:residueName")) {
141
aminoAcid.setProperty(RESIDUE_NAME, ac.getProperty(dictRef).toString().toUpperCase());
142
aminoAcid.setMonomerName(ac.getProperty(dictRef).toString());
143
} else if (dictRef.getType().equals("pdb:oneLetterCode")) {
144
aminoAcid.setProperty(RESIDUE_NAME_SHORT, ac.getProperty(dictRef));
145
} else if (dictRef.getType().equals("pdb:id")) {
146
aminoAcid.setProperty(ID, ac.getProperty(dictRef));
147
logger.debug("Set AA ID to: ", ac.getProperty(dictRef));
149
logger.error("Cannot deal with dictRef!");
153
while (atoms.hasNext()) {
154
org.openscience.cdk.interfaces.IAtom atom = (IAtom)atoms.next();
155
String dictRef = (String)atom.getProperty("org.openscience.cdk.dict");
156
if (dictRef != null && dictRef.equals("pdb:nTerminus")) {
157
aminoAcid.addNTerminus(atom);
158
} else if (dictRef != null && dictRef.equals("pdb:cTerminus")) {
159
aminoAcid.addCTerminus(atom);
161
aminoAcid.addAtom(atom);
164
// org.openscience.cdk.interfaces.IBond[] bonds = ac.getBonds();
165
Iterator bonds = ac.bonds();
166
while (bonds.hasNext()) {
167
IBond bond = (IBond) bonds.next();
168
aminoAcid.addBond(bond);
170
AminoAcidManipulator.removeAcidicOxygen(aminoAcid);
171
aminoAcid.setProperty(NO_ATOMS, "" + aminoAcid.getAtomCount());
172
aminoAcid.setProperty(NO_BONDS, "" + aminoAcid.getBondCount());
173
if (counter < aminoAcids.length) {
174
aminoAcids[counter] = aminoAcid;
176
logger.error("Could not store AminoAcid! Array too short!");
180
} catch (Exception exception) {
181
logger.error("Failed reading file: ", exception.getMessage());
182
logger.debug(exception);
189
* Returns a HashMap where the key is one of G, A, V, L, I, S, T, C, M, D,
190
* N, E, Q, R, K, H, F, Y, W and P.
192
public static HashMap getHashMapBySingleCharCode() {
193
AminoAcid[] monomers = createAAs();
194
HashMap map = new HashMap();
195
for (int i=0; i<monomers.length; i++) {
196
map.put(monomers[i].getProperty(RESIDUE_NAME_SHORT), monomers[i]);
202
* Returns a HashMap where the key is one of GLY, ALA, VAL, LEU, ILE, SER,
203
* THR, CYS, MET, ASP, ASN, GLU, GLN, ARG, LYS, HIS, PHE, TYR, TRP AND PRO.
205
public static HashMap getHashMapByThreeLetterCode() {
206
AminoAcid[] monomers = createAAs();
207
HashMap map = new HashMap();
208
for (int i=0; i<monomers.length; i++) {
209
map.put(monomers[i].getProperty(RESIDUE_NAME), monomers[i]);
215
* Returns the one letter code of an amino acid given a three letter code.
216
* For example, it will return "V" when "Val" was passed.
218
public static String convertThreeLetterCodeToOneLetterCode(String threeLetterCode) {
219
AminoAcid[] monomers = createAAs();
220
for (int i=0; i<monomers.length; i++) {
221
if (monomers[i].getProperty(RESIDUE_NAME).equals(threeLetterCode)) {
222
return (String)monomers[i].getProperty(RESIDUE_NAME_SHORT);
229
* Returns the three letter code of an amino acid given a one letter code.
230
* For example, it will return "Val" when "V" was passed.
232
public static String convertOneLetterCodeToThreeLetterCode(String oneLetterCode) {
233
AminoAcid[] monomers = createAAs();
234
for (int i=0; i<monomers.length; i++) {
235
if (monomers[i].getProperty(RESIDUE_NAME_SHORT).equals(oneLetterCode)) {
236
return (String)monomers[i].getProperty(RESIDUE_NAME);