1- package org .biojava .bio .structure ;
1+ package org .biojava .bio .structure . asa ;
22
33import java .util .ArrayList ;
4+ import java .util .TreeMap ;
45import java .util .concurrent .ExecutorService ;
56import java .util .concurrent .Executors ;
67
78import javax .vecmath .Point3d ;
89
10+ import org .biojava .bio .structure .AminoAcid ;
11+ import org .biojava .bio .structure .Atom ;
12+ import org .biojava .bio .structure .Calc ;
13+ import org .biojava .bio .structure .Element ;
14+ import org .biojava .bio .structure .Group ;
15+ import org .biojava .bio .structure .GroupType ;
16+ import org .biojava .bio .structure .NucleotideImpl ;
17+ import org .biojava .bio .structure .ResidueNumber ;
18+ import org .biojava .bio .structure .Structure ;
19+ import org .biojava .bio .structure .StructureException ;
20+ import org .biojava .bio .structure .StructureTools ;
21+
922
1023
1124
@@ -76,14 +89,16 @@ public void run() {
7689 private double cons ;
7790
7891 /**
79- * Constructs a new AsaCalculator. Subsequently call {@link #calculateAsa()}
80- * to calculate the ASAs.
92+ * Constructs a new AsaCalculator. Subsequently call {@link #calculateAsas()}
93+ * or {@link #getGroupAsas()} to calculate the ASAs
94+ * Only non-Hydrogen atoms are considered in the calculation.
8195 * @param structure
8296 * @param probe
8397 * @param nSpherePoints
8498 * @param nThreads
8599 * @param hetAtoms if true HET residues are considered, if false they aren't, equivalent to
86100 * NACCESS' -h option
101+ * @see StructureTools.getAllNonHAtomArray
87102 */
88103 public AsaCalculator (Structure structure , double probe , int nSpherePoints , int nThreads , boolean hetAtoms ) {
89104 this .atoms = StructureTools .getAllNonHAtomArray (structure , hetAtoms );
@@ -103,8 +118,8 @@ public AsaCalculator(Structure structure, double probe, int nSpherePoints, int n
103118 }
104119
105120 /**
106- * Constructs a new AsaCalculator. Subsequently call {@link #calculateAsa ()}
107- * to calculate the ASAs.
121+ * Constructs a new AsaCalculator. Subsequently call {@link #calculateAsas ()}
122+ * or {@link #getGroupAsas()} to calculate the ASAs.
108123 * @param atoms an array of atoms not containing Hydrogen atoms
109124 * @param probe the probe size
110125 * @param nSpherePoints the number of points to be used in generating the spherical
@@ -134,13 +149,41 @@ public AsaCalculator(Atom[] atoms, double probe, int nSpherePoints, int nThreads
134149 cons = 4.0 * Math .PI / (double )nSpherePoints ;
135150 }
136151
152+ /**
153+ * Calculates ASA for all atoms and return them as a GroupAsa
154+ * array (one element per residue in structure) containing ASAs per residue
155+ * and per atom.
156+ * The sorting of Groups in returned array is as specified by {@link org.biojava.bio.structure.ResidueNumber}
157+ * @return
158+ */
159+ public GroupAsa [] getGroupAsas () {
160+
161+ TreeMap <ResidueNumber , GroupAsa > asas = new TreeMap <ResidueNumber , GroupAsa >();
162+
163+ double [] asasPerAtom = calculateAsas ();
164+
165+ for (int i =0 ;i <atoms .length ;i ++) {
166+ Group g = atoms [i ].getGroup ();
167+ if (!asas .containsKey (g .getResidueNumber ())) {
168+ GroupAsa groupAsa = new GroupAsa (g );
169+ groupAsa .addAtomAsaU (asasPerAtom [i ]);
170+ asas .put (g .getResidueNumber (), groupAsa );
171+ } else {
172+ GroupAsa groupAsa = asas .get (g .getResidueNumber ());
173+ groupAsa .addAtomAsaU (asasPerAtom [i ]);
174+ }
175+ }
176+
177+ return (GroupAsa []) asas .values ().toArray (new GroupAsa [asas .size ()]);
178+ }
179+
137180 /**
138181 * Calculates the Accessible Surface Areas for the atoms given in constructor and with parameters given.
139182 * Beware that the parallel implementation is quite memory hungry. It scales well as long as there is
140183 * enough memory available.
141184 * @return an array with asa values corresponding to each atom of the input array
142185 */
143- public double [] calculateAsa () {
186+ public double [] calculateAsas () {
144187
145188 double [] asas = new double [atoms .length ];
146189
@@ -333,7 +376,7 @@ else if (atomCode.equals("CA") || atomCode.equals("CB") ||
333376 atomCode .equals ("CG1" ) || atomCode .equals ("CG2" )) {
334377 return TETRAHEDRAL_CARBON_VDW ; // tetrahedral Carbon
335378 }
336- // left cases depend on amino acid: CD, CD1, CD2, CG
379+ // the rest of the cases ( CD, CD1, CD2, CG) depend on amino acid
337380 else {
338381 switch (aa ) {
339382 case 'F' :
0 commit comments