From d5d09741df0f938998ab7f7cd117c26e4c593262 Mon Sep 17 00:00:00 2001 From: Mitch Miller Date: Wed, 8 May 2024 15:58:06 -0400 Subject: [PATCH] made ringsSearcherSupplier resistent to exceptions thrown by AllRingsFinder --- .../gov/nih/ncats/molwitch/cdk/CdkChemicalImpl.java | 6 ++++-- .../org/openscience/cdk/geometry/cip/CIPToolMod.java | 2 +- src/test/java/TestChiralRead.java | 10 +++++++++- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/main/java/gov/nih/ncats/molwitch/cdk/CdkChemicalImpl.java b/src/main/java/gov/nih/ncats/molwitch/cdk/CdkChemicalImpl.java index 313ee29..5564070 100644 --- a/src/main/java/gov/nih/ncats/molwitch/cdk/CdkChemicalImpl.java +++ b/src/main/java/gov/nih/ncats/molwitch/cdk/CdkChemicalImpl.java @@ -449,8 +449,10 @@ public static void setMaxUndefinedStereoCenters(int maxUndefinedStereoCenters) { } } return 1; - } catch (CDKException e) { - throw new RuntimeException(e); + } catch (CDKException | IllegalArgumentException e) { + Logger.getLogger(this.getClass().getName()).fine(String.format("Error processing rings in molecule with formula %s (%s; ring size limit %d)", + this.getFormula(), e.getMessage(), Math.min(container.getAtomCount(),12))); + return 0; } diff --git a/src/main/java/org/openscience/cdk/geometry/cip/CIPToolMod.java b/src/main/java/org/openscience/cdk/geometry/cip/CIPToolMod.java index 3cffb5b..9a24ed1 100644 --- a/src/main/java/org/openscience/cdk/geometry/cip/CIPToolMod.java +++ b/src/main/java/org/openscience/cdk/geometry/cip/CIPToolMod.java @@ -300,7 +300,7 @@ public static int getSizeOfLargestRingSystem(CdkChemicalImpl chemical) { } } bondsToRemove.forEach(b-> copy.removeBond(b)); - + if( copy.getBondCount() == 0) { //we have removed all non-ring bonds. When we have no bonds, that means no rings return 0; diff --git a/src/test/java/TestChiralRead.java b/src/test/java/TestChiralRead.java index 0eab2b8..b3425dd 100644 --- a/src/test/java/TestChiralRead.java +++ b/src/test/java/TestChiralRead.java @@ -20,7 +20,9 @@ */ import java.io.File; +import java.io.FileInputStream; import java.io.IOException; +import java.io.InputStream; import java.nio.file.Files; import java.util.Arrays; import java.util.Date; @@ -28,6 +30,7 @@ import java.util.Optional; import java.util.stream.Collectors; +import com.simolecule.centres.CdkMol; import gov.nih.ncats.molwitch.TetrahedralChirality; import gov.nih.ncats.molwitch.cdk.CdkChemicalImpl; import org.apache.commons.io.IOUtils; @@ -38,7 +41,13 @@ import gov.nih.ncats.molwitch.Chirality; import gov.nih.ncats.molwitch.Stereocenter; import gov.nih.ncats.molwitch.io.ChemicalReaderFactory; +import org.openscience.cdk.AtomContainer; import org.openscience.cdk.geometry.cip.CIPToolMod; +import org.openscience.cdk.interfaces.IAtomContainer; +import org.openscience.cdk.interfaces.IRingSet; +import org.openscience.cdk.io.MDLV2000Reader; +import org.openscience.cdk.io.Mol2Reader; +import org.openscience.cdk.ringsearch.AllRingsFinder; import static org.junit.Assert.*; @@ -1938,5 +1947,4 @@ public void testRingSystem3() throws Exception { assertEquals(5, ringSystemCount); } - }