Skip to content

Commit

Permalink
Remove non-loops. RandomAccessSDFReader had a comment that MDLV2000Re…
Browse files Browse the repository at this point in the history
…ader(IAtomContainer) didn't read properties which is why it used a IChemModel - this is no longer the case. The reset were cases where we want to select the first match.
  • Loading branch information
johnmay authored and egonw committed Feb 19, 2022
1 parent 3a56550 commit 5a0e966
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 32 deletions.
Expand Up @@ -148,9 +148,8 @@ public Object visit(ASTRingIdentifier node, Object data) {

public Object visit(ASTAtom node, Object data) {
IQueryAtom atom = (IQueryAtom) node.jjtGetChild(0).jjtAccept(this, data);
for (int i = 1; i < node.jjtGetNumChildren(); i++) { // if there are ring identifiers
if (node.jjtGetNumChildren() > 1) // if there are ring identifiers
throw new IllegalStateException();
}
return atom;
}

Expand Down
Expand Up @@ -329,11 +329,11 @@ public synchronized void sortResultsByEnergies() throws CDKException {
boolean flag = false;

double lowestEnergyScore = 99999999.99;
for (Integer key : energySelectionMap.keySet()) {
if (energySelectionMap.size() > 0) {
Integer key = energySelectionMap.keySet().iterator().next();
lowestEnergyScore = energySelectionMap.get(key);
flag = true;
clear();
break;
}

int counter = 0;
Expand Down
Expand Up @@ -84,29 +84,7 @@ public IResourceFormat getFormat() {

@Override
protected IChemObject processContent() throws CDKException {
/*
* return chemObjectReader.read(builder.newInstance(IAtomContainer.class));
*/
//read(IAtomContainer) doesn't read properties ...
IChemObject co = chemObjectReader.read(builder.newInstance(IChemFile.class));
if (co instanceof IChemFile) {
int c = ((IChemFile) co).getChemSequenceCount();
for (int i = 0; i < c; i++) {
for (IChemModel iChemModel : ((IChemFile) co).getChemSequence(i).chemModels()) {
for (IAtomContainer container : iChemModel.getMoleculeSet().atomContainers()) {

co = container;
break;
}
break;
}
Iterator<IChemModel> cm = null;
break;
}
//cs = null;
}
return co;

return chemObjectReader.read(builder.newAtomContainer());
}

public void setReader(Reader reader) throws CDKException {
Expand Down
Expand Up @@ -350,7 +350,9 @@ boolean assignLayout(IAtomContainer container) {
String smiles = cansmi(container, ordering);

// find the points in the library
for (Point2d[] points : templateMap.getOrDefault(smiles, Collections.emptyList())) {
List<Point2d[]> templatePoints = templateMap.get(smiles);
if (templatePoints != null && templatePoints.size() > 0) {
Point2d[] points = templatePoints.get(0);
// set the points
for (int i = 0; i < n; i++) {
container.getAtom(i).setPoint2d(new Point2d(points[ordering[i]]));
Expand Down
Expand Up @@ -54,6 +54,7 @@
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -330,8 +331,9 @@ public static TemplateHandler createSingleton(IAtomContainer template) {
*/
public static TemplateHandler createFromSubstructure(Pattern ptrn, Iterable<IAtomContainer> mols) {
for (IAtomContainer mol : mols) {
for (IAtomContainer template : ptrn.matchAll(mol).toSubstructures())
return createSingleton(template);
Iterator<IAtomContainer> matched = ptrn.matchAll(mol).toSubstructures().iterator();
if (matched.hasNext())
return createSingleton(matched.next());
}
throw new IllegalArgumentException("Pattern does not match any provided molecules");
}
Expand All @@ -345,8 +347,9 @@ public static TemplateHandler createFromSubstructure(Pattern ptrn, Iterable<IAto
* @return new template handler
*/
public static TemplateHandler createFromSubstructure(Pattern ptrn, IAtomContainer mol) {
for (IAtomContainer template : ptrn.matchAll(mol).toSubstructures())
return createSingleton(template);
Iterator<IAtomContainer> matched = ptrn.matchAll(mol).toSubstructures().iterator();
if (matched.hasNext())
return createSingleton(matched.next());
throw new IllegalArgumentException("Pattern does not match any provided molecules");
}

Expand Down

0 comments on commit 5a0e966

Please sign in to comment.