Skip to content

Commit

Permalink
made ringsSearcherSupplier resistent to exceptions thrown by AllRings…
Browse files Browse the repository at this point in the history
…Finder
  • Loading branch information
ChemMitch committed May 8, 2024
1 parent 1ad7b24 commit d5d0974
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/main/java/gov/nih/ncats/molwitch/cdk/CdkChemicalImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 9 additions & 1 deletion src/test/java/TestChiralRead.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,17 @@
*/

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;
import java.util.List;
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;
Expand All @@ -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.*;

Expand Down Expand Up @@ -1938,5 +1947,4 @@ public void testRingSystem3() throws Exception {

assertEquals(5, ringSystemCount);
}

}

0 comments on commit d5d0974

Please sign in to comment.