3030
3131import javax .vecmath .Point3d ;
3232import java .util .ArrayList ;
33- import java .util .Iterator ;
34- import org .openscience .cdk .geometry .surface .Point_Type ;
33+ import java .util .List ;
3534
3635/**
3736 * A class representing the solvent accessible surface area surface of a molecule.
5958public class NumericalSurface {
6059
6160 private static ILoggingTool logger = LoggingToolFactory .createLoggingTool (NumericalSurface .class );
62- double solventRadius = 1.4 ;
63- int tesslevel = 4 ;
64- IAtom [] atoms ;
65- ArrayList [] surfPoints ;
66- double [] areas ;
67- double [] volumes ;
61+ double solventRadius = 1.4 ;
62+ int tesslevel = 4 ;
63+ IAtom [] atoms ;
64+ List < Point3d >[] surfPoints ;
65+ double [] areas ;
66+ double [] volumes ;
6867
6968 /**
7069 * Constructor to initialize the surface calculation with default values.
@@ -125,14 +124,14 @@ private void init() {
125124 // get r_f and geometric center
126125 Point3d cp = new Point3d (0 , 0 , 0 );
127126 double maxRadius = 0 ;
128- for (int i = 0 ; i < atoms . length ; i ++ ) {
129- double vdwr = PeriodicTable .getVdwRadius (atoms [ i ] .getSymbol ());
127+ for (IAtom atom : atoms ) {
128+ double vdwr = PeriodicTable .getVdwRadius (atom .getSymbol ());
130129 if (vdwr + solventRadius > maxRadius )
131- maxRadius = PeriodicTable .getVdwRadius (atoms [ i ] .getSymbol ()) + solventRadius ;
130+ maxRadius = PeriodicTable .getVdwRadius (atom .getSymbol ()) + solventRadius ;
132131
133- cp .x = cp .x + atoms [ i ] .getPoint3d ().x ;
134- cp .y = cp .y + atoms [ i ] .getPoint3d ().y ;
135- cp .z = cp .z + atoms [ i ] .getPoint3d ().z ;
132+ cp .x = cp .x + atom .getPoint3d ().x ;
133+ cp .y = cp .y + atom .getPoint3d ().y ;
134+ cp .z = cp .z + atom .getPoint3d ().z ;
136135 }
137136 cp .x = cp .x / atoms .length ;
138137 cp .y = cp .y / atoms .length ;
@@ -154,7 +153,7 @@ private void init() {
154153 */
155154
156155 // loop over atoms and get surface points
157- this .surfPoints = new ArrayList [atoms .length ];
156+ this .surfPoints = ( List < Point3d >[]) new List [atoms .length ];
158157 this .areas = new double [atoms .length ];
159158 this .volumes = new double [atoms .length ];
160159
@@ -177,36 +176,30 @@ private void init() {
177176 */
178177 public Point3d [] getAllSurfacePoints () {
179178 int npt = 0 ;
180- for (int i = 0 ; i < this .surfPoints . length ; i ++ )
181- npt += this . surfPoints [ i ] .size ();
179+ for (List < Point3d > surfPoint : this .surfPoints )
180+ npt += surfPoint .size ();
182181 Point3d [] ret = new Point3d [npt ];
183182 int j = 0 ;
184- for (int i = 0 ; i < this .surfPoints .length ; i ++) {
185- ArrayList arl = this .surfPoints [i ];
186- for (Iterator it = arl .iterator (); it .hasNext ();) {
187- ret [j ] = (Point3d ) it .next ();
188- j ++;
183+ for (List <Point3d > points : this .surfPoints ) {
184+ for (Point3d p : points ) {
185+ ret [j ++] = p ;
189186 }
190187 }
191188 return (ret );
192189 }
193190
194191 public ArrayList <Point_Type > getAllPointswithAtomType () {
195192 int npt = 0 ;
196- for (int i = 0 ; i < this .surfPoints .length ; i ++)
197- npt += this .surfPoints [i ].size ();
198- //Point3d[] ret = new Point3d[npt];
193+ for (List <Point3d > surfPoint : this .surfPoints )
194+ npt += surfPoint .size ();
199195 ArrayList <Point_Type > point_types = new ArrayList <Point_Type >(npt );
200- //ArrayList<Integer> atomtype = new ArrayList<Integer>(npt);
201196 int j = 0 ;
202197 for (int i = 0 ; i < this .surfPoints .length ; i ++) {
203- ArrayList arl = this .surfPoints [i ];
204- //atomtype.add(this.atoms[i].getAtomicNumber());
205- for (Iterator it = arl .iterator (); it .hasNext ();) {
206- //ret[j] = (Point3d) it.next();
198+ List <Point3d > arl = this .surfPoints [i ];
199+ for (Point3d p : arl ) {
207200 Point_Type point_type = new Point_Type ();
208201 point_type .setAtom (this .atoms [i ].getAtomicNumber ());
209- point_type .setCoord (( Point3d ) it . next () );
202+ point_type .setCoord (p );
210203 point_types .add (point_type );
211204 j ++;
212205 }
@@ -223,14 +216,9 @@ public ArrayList<Point_Type> getAllPointswithAtomType() {
223216 * @throws CDKException if the atom index is outside the range of allowable indices
224217 */
225218 public Point3d [] getSurfacePoints (int atomIdx ) throws CDKException {
226- if (atomIdx >= this .surfPoints .length ) {
219+ if (atomIdx >= this .surfPoints .length )
227220 throw new CDKException ("Atom index was out of bounds" );
228- }
229- ArrayList arl = this .surfPoints [atomIdx ];
230- Point3d [] ret = new Point3d [arl .size ()];
231- for (int i = 0 ; i < arl .size (); i ++)
232- ret [i ] = (Point3d ) arl .get (i );
233- return (ret );
221+ return this .surfPoints [atomIdx ].toArray (new Point3d [0 ]);
234222 }
235223
236224 /**
@@ -242,10 +230,9 @@ public Point3d[] getSurfacePoints(int atomIdx) throws CDKException {
242230 * @throws CDKException if the atom index is outside the range of allowable indices
243231 */
244232 public double getSurfaceArea (int atomIdx ) throws CDKException {
245- if (atomIdx >= this .surfPoints .length ) {
233+ if (atomIdx >= this .surfPoints .length )
246234 throw new CDKException ("Atom index was out of bounds" );
247- }
248- return (this .areas [atomIdx ]);
235+ return this .areas [atomIdx ];
249236 }
250237
251238 /**
@@ -254,7 +241,7 @@ public double getSurfaceArea(int atomIdx) throws CDKException {
254241 * @return An array of double giving the surface areas of all the atoms
255242 */
256243 public double [] getAllSurfaceAreas () {
257- return ( this .areas ) ;
244+ return this .areas ;
258245 }
259246
260247 /**
@@ -265,9 +252,9 @@ public double[] getAllSurfaceAreas() {
265252 */
266253 public double getTotalSurfaceArea () {
267254 double ta = 0.0 ;
268- for (int i = 0 ; i < this .areas . length ; i ++ )
269- ta += this . areas [ i ] ;
270- return ( ta ) ;
255+ for (double area : this .areas )
256+ ta += area ;
257+ return ta ;
271258 }
272259
273260 private void translatePoints (int atmIdx , Point3d [][] points , int pointDensity , IAtom atom , Point3d cp ) {
@@ -278,8 +265,8 @@ private void translatePoints(int atmIdx, Point3d[][] points, int pointDensity, I
278265 double sumx = 0.0 ;
279266 double sumy = 0.0 ;
280267 double sumz = 0.0 ;
281- for (int i = 0 ; i < points . length ; i ++ ) {
282- Point3d p = points [ i ] [1 ];
268+ for (Point3d [] point : points ) {
269+ Point3d p = point [1 ];
283270 sumx += p .x ;
284271 sumy += p .y ;
285272 sumz += p .z ;
@@ -293,9 +280,9 @@ private void translatePoints(int atmIdx, Point3d[][] points, int pointDensity, I
293280 this .areas [atmIdx ] = area ;
294281 this .volumes [atmIdx ] = volume ;
295282
296- ArrayList tmp = new ArrayList ();
297- for (int i = 0 ; i < points . length ; i ++ )
298- tmp .add (points [ i ] [0 ]);
283+ List < Point3d > tmp = new ArrayList <> ();
284+ for (Point3d [] point : points )
285+ tmp .add (point [0 ]);
299286 this .surfPoints [atmIdx ] = tmp ;
300287 }
301288
@@ -324,20 +311,19 @@ private Point3d[][] atomicSurfacePoints(NeighborList nbrlist, int currAtomIdx, I
324311 }
325312
326313 Point3d [] tessPoints = tess .getTessAsPoint3ds ();
327- ArrayList points = new ArrayList ();
328- for (int i = 0 ; i < tessPoints .length ; i ++) {
329- Point3d pt = tessPoints [i ];
314+ List <Point3d []> points = new ArrayList <>();
315+ for (Point3d pt : tessPoints ) {
330316 boolean buried = false ;
331- for (int j = 0 ; j < data . length ; j ++ ) {
332- if (data [ j ][ 0 ] * pt .x + data [ j ][ 1 ] * pt .y + data [ j ][ 2 ] * pt .z > data [ j ] [3 ]) {
317+ for (double [] datum : data ) {
318+ if (datum [ 0 ] * pt .x + datum [ 1 ] * pt .y + datum [ 2 ] * pt .z > datum [3 ]) {
333319 buried = true ;
334320 break ;
335321 }
336322 }
337- if (buried == false ) {
323+ if (! buried ) {
338324 Point3d [] tmp = new Point3d [2 ];
339325 tmp [0 ] = new Point3d (totalRadius * pt .x + atom .getPoint3d ().x , totalRadius * pt .y
340- + atom .getPoint3d ().y , totalRadius * pt .z + atom .getPoint3d ().z );
326+ + atom .getPoint3d ().y , totalRadius * pt .z + atom .getPoint3d ().z );
341327 tmp [1 ] = pt ;
342328 points .add (tmp );
343329 }
@@ -348,7 +334,7 @@ private Point3d[][] atomicSurfacePoints(NeighborList nbrlist, int currAtomIdx, I
348334 // original unit tesselation
349335 Point3d [][] ret = new Point3d [points .size ()][2 ];
350336 for (int i = 0 ; i < points .size (); i ++) {
351- Point3d [] tmp = ( Point3d []) points .get (i );
337+ Point3d [] tmp = points .get (i );
352338 ret [i ][0 ] = tmp [0 ];
353339 ret [i ][1 ] = tmp [1 ];
354340 }
0 commit comments