128128@ TestClass ("org.openscience.cdk.qsar.descriptors.molecular.BCUTDescriptorTest" )
129129public class BCUTDescriptor implements IMolecularDescriptor {
130130 private static ILoggingTool logger =
131- LoggingToolFactory .createLoggingTool (BCUTDescriptor .class );
131+ LoggingToolFactory .createLoggingTool (BCUTDescriptor .class );
132132
133133 // the number of negative & positive eigenvalues
134134 // to return for each class of BCUT descriptor
@@ -201,7 +201,7 @@ public Object[] getParameters() {
201201 return (params );
202202 }
203203
204- @ TestMethod (value = "testNamesConsistency" )
204+ @ TestMethod ("testNamesConsistency" )
205205 public String [] getDescriptorNames () {
206206 String [] names ;
207207 String [] suffix = {"w" , "c" , "p" };
@@ -250,12 +250,20 @@ public Object getParameterType(String name) {
250250 return (object );
251251 }
252252
253+ private boolean hasUndefined (double [][] m ) {
254+ for (double [] aM : m ) {
255+ for (int j = 0 ; j < m [0 ].length ; j ++) {
256+ if (Double .isNaN (aM [j ]) || Double .isInfinite (aM [j ])) return true ;
257+ }
258+ }
259+ return false ;
260+ }
253261
254262 static private class BurdenMatrix {
255263
256264 static double [][] evalMatrix (IAtomContainer atomContainer , double [] vsd ) {
257265 IAtomContainer local = AtomContainerManipulator .removeHydrogens (atomContainer );
258-
266+
259267 int natom = local .getAtomCount ();
260268 double [][] matrix = new double [natom ][natom ];
261269 for (int i = 0 ; i < natom ; i ++) {
@@ -303,7 +311,7 @@ static double[][] evalMatrix(IAtomContainer atomContainer, double[] vsd) {
303311 * @return An ArrayList containing the descriptors. The default is to return
304312 * all calculated eigenvalues of the Burden matrices in the order described
305313 * above. If a parameter list was supplied, then only the specified number
306- * of highest and lowest eigenvalues (for each class of BCUT) will be returned.
314+ * of highest and lowest eigenvalues (for each class of BCUT) will be returned.
307315 */
308316 @ TestMethod ("testCalculate_IAtomContainer" )
309317 public DescriptorValue calculate (IAtomContainer container ) {
@@ -318,7 +326,7 @@ public DescriptorValue calculate(IAtomContainer container) {
318326
319327 // add H's in case they're not present
320328 try {
321- AtomContainerManipulator .percieveAtomTypesAndConfigureAtoms (molecule );
329+ AtomContainerManipulator .percieveAtomTypesAndConfigureAtoms (molecule );
322330 CDKHydrogenAdder hAdder = CDKHydrogenAdder .getInstance (molecule .getBuilder ());
323331 hAdder .addImplicitHydrogens (molecule );
324332 AtomContainerManipulator .convertImplicitToExplicitHydrogens (molecule );
@@ -336,7 +344,7 @@ public DescriptorValue calculate(IAtomContainer container) {
336344 try {
337345 CDKHueckelAromaticityDetector .detectAromaticity (molecule );
338346 } catch (CDKException e ) {
339- return getDummyDescriptorValue (new CDKException ("Error in aromaticity perception: " + e .getMessage ()));
347+ return getDummyDescriptorValue (new CDKException ("Error in aromaticity perception: " + e .getMessage ()));
340348 }
341349 }
342350
@@ -364,10 +372,12 @@ public DescriptorValue calculate(IAtomContainer container) {
364372 }
365373
366374 double [][] burdenMatrix = BurdenMatrix .evalMatrix (molecule , diagvalue );
375+ if (!hasUndefined (burdenMatrix ))
376+ return getDummyDescriptorValue (new CDKException ("Burden matrix has undefined values" ));
367377 Matrix matrix = new Matrix (burdenMatrix );
368378 EigenvalueDecomposition eigenDecomposition = new EigenvalueDecomposition (matrix );
369379 double [] eval1 = eigenDecomposition .getRealEigenvalues ();
370-
380+
371381 // get charge weighted BCUT
372382 LonePairElectronChecker lpcheck = new LonePairElectronChecker ();
373383 GasteigerPEPEPartialCharges pepe ;
@@ -393,7 +403,9 @@ public DescriptorValue calculate(IAtomContainer container) {
393403 diagvalue [counter ] = molecule .getAtom (i ).getCharge ();
394404 counter ++;
395405 }
396- burdenMatrix = BurdenMatrix .evalMatrix (molecule , diagvalue );
406+ burdenMatrix = BurdenMatrix .evalMatrix (molecule , diagvalue );
407+ if (!hasUndefined (burdenMatrix ))
408+ return getDummyDescriptorValue (new CDKException ("Burden matrix has undefined values" ));
397409 matrix = new Matrix (burdenMatrix );
398410 eigenDecomposition = new EigenvalueDecomposition (matrix );
399411 double [] eval2 = eigenDecomposition .getRealEigenvalues ();
@@ -405,11 +417,13 @@ public DescriptorValue calculate(IAtomContainer container) {
405417 Polarizability pol = new Polarizability ();
406418 counter = 0 ;
407419 for (int i = 0 ; i < molecule .getAtomCount (); i ++) {
408- if (molecule .getAtom (i ).getSymbol ().equals ("H" )) continue ;
420+ if (molecule .getAtom (i ).getSymbol ().equals ("H" )) continue ;
409421 diagvalue [counter ] = pol .calculateGHEffectiveAtomPolarizability (molecule , molecule .getAtom (i ), false , topoDistance );
410422 counter ++;
411423 }
412424 burdenMatrix = BurdenMatrix .evalMatrix (molecule , diagvalue );
425+ if (!hasUndefined (burdenMatrix ))
426+ return getDummyDescriptorValue (new CDKException ("Burden matrix has undefined values" ));
413427 matrix = new Matrix (burdenMatrix );
414428 eigenDecomposition = new EigenvalueDecomposition (matrix );
415429 double [] eval3 = eigenDecomposition .getRealEigenvalues ();
@@ -435,7 +449,7 @@ public DescriptorValue calculate(IAtomContainer container) {
435449 enhigh = 0 ;
436450 }
437451
438- DoubleArrayResult retval = new DoubleArrayResult ( (lnlow + enlow + lnhigh + enhigh ) * 3 );
452+ DoubleArrayResult retval = new DoubleArrayResult ((lnlow + enlow + lnhigh + enhigh ) * 3 );
439453
440454 for (int i = 0 ; i < lnlow ; i ++) retval .add (eval1 [i ]);
441455 for (int i = 0 ; i < enlow ; i ++) retval .add (Double .NaN );
0 commit comments