Skip to content

Commit

Permalink
renamed maxUndefined to maxUndefinedStereoCenters
Browse files Browse the repository at this point in the history
cleaned up atom deletion in getSizeOfLargestRingSystem
prevent double calls to getSizeOfLargestRingSystem
use real logging instead of println
  • Loading branch information
ChemMitch committed May 9, 2024
1 parent d5d0974 commit 431914e
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.io.StringReader;
import java.util.Map;
import java.util.function.Consumer;
import java.util.logging.Logger;
import java.util.stream.Stream;

import org.openscience.cdk.atomtype.CDKAtomTypeMatcher;
Expand Down Expand Up @@ -532,14 +533,16 @@ public boolean isDefault() {

@Override
public void applyParameters(Map<String, Object> params){
System.out.println("in CdkChemical2FactoryImpl.applyParameters");
Logger.getLogger(this.getClass().getName()).fine("in CdkChemical2FactoryImpl.applyParameters");
if( params.get("complexityCutoff") != null) {
CdkChemicalImpl.setComplexityCutoff((Integer) params.get("complexityCutoff"));
System.out.printf("complexityCutoff: %s\n", params.get("complexityCutoff"));
Logger.getLogger(this.getClass().getName()).fine(
String.format("complexityCutoff: %s\n", params.get("complexityCutoff")));
}
if( params.get("maxUndefined") != null ) {
CdkChemicalImpl.setMaxUndefinedStereoCenters((Integer)params.get("maxUndefined"));
System.out.printf("maxUndefined: %s\n", params.get("maxUndefined"));
if( params.get("maxUndefinedStereoCenters") != null ) {
CdkChemicalImpl.setMaxUndefinedStereoCenters((Integer)params.get("maxUndefinedStereoCenters"));
Logger.getLogger(this.getClass().getName()).fine(
String.format("maxUndefinedStereoCenters: %s\n", params.get("maxUndefinedStereoCenters")));
}
}
}
9 changes: 6 additions & 3 deletions src/main/java/gov/nih/ncats/molwitch/cdk/CdkChemicalImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ public static void setMaxUndefinedStereoCenters(int maxUndefinedStereoCenters) {
CdkChemicalImpl.maxUndefinedStereoCenters = maxUndefinedStereoCenters;
}

private static int maxUndefinedStereoCenters = 20;
//This parameter allows us to prevent a long calculation that enumerates all possibilities of undefined stereocenters.
// this should typically be set to values < 10
private static int maxUndefinedStereoCenters = 5;

// CDKAtomTypeMatcher matcher = CDKAtomTypeMatcher.getInstance(SilentChemObjectBuilder.getInstance());

Expand Down Expand Up @@ -215,8 +217,9 @@ public static void setMaxUndefinedStereoCenters(int maxUndefinedStereoCenters) {
}

CachedSupplier<Boolean> complexitySupplier =CachedSupplier.of(()->{
Logger.getLogger(this.getClass().getName()).info("getSizeOfLargestRingSystem(this): " + getSizeOfLargestRingSystem(this));
return getSizeOfLargestRingSystem(this)> complexityCutoff;
int sizeOfLargestRingSystem = getSizeOfLargestRingSystem(this);
Logger.getLogger(this.getClass().getName()).info("getSizeOfLargestRingSystem(this): " + sizeOfLargestRingSystem);
return sizeOfLargestRingSystem > complexityCutoff;
});

CachedSupplier<Integer> perceiveAtomTypesOfNonQueryAtoms = CachedSupplier.of(()->{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,16 @@ public static int getSizeOfLargestRingSystem(CdkChemicalImpl chemical) {
return 0;
}

List<Atom> atomsToRemove = new ArrayList<>();
for(int i = copy.getAtomCount()-1; i >=0; i--) {
Atom atom = copy.getAtom(i);
if(atom.getBondCount() == 0) {
//System.out.printf("atom %d of symbol %s has no bonds and will be deleted\n", i, atom.getSymbol());
copy.removeAtom(i);
//copy.removeAtom(i);
atomsToRemove.add(atom);
}
}

ChemObject chemObject = new ChemObject();
atomsToRemove.forEach(a->copy.removeAtom(a));

Iterator<CdkChemicalImpl> iterator = copy.connectedComponents();
int fragmentCount=0;
Expand Down

0 comments on commit 431914e

Please sign in to comment.