Skip to content

Commit

Permalink
Use atom index instead of linear scan.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmay committed Feb 22, 2016
1 parent 5b1ab1a commit d5a6914
Showing 1 changed file with 9 additions and 9 deletions.
Expand Up @@ -475,7 +475,7 @@ public void writeMolecule(IAtomContainer container) throws Exception {
}
}
}

line += String.format(" 0 0 %d 0 0", parity);
}

Expand Down Expand Up @@ -584,11 +584,11 @@ else if (valence > 0 && valence < 15)
if (bond.getStereo() == IBond.Stereo.UP_INVERTED || bond.getStereo() == IBond.Stereo.DOWN_INVERTED
|| bond.getStereo() == IBond.Stereo.UP_OR_DOWN_INVERTED) {
// turn around atom coding to correct for inv stereo
line = formatMDLInt(container.getAtomNumber(bond.getAtom(1)) + 1, 3);
line += formatMDLInt(container.getAtomNumber(bond.getAtom(0)) + 1, 3);
line = formatMDLInt(atomindex.get(bond.getAtom(1)) + 1, 3);
line += formatMDLInt(atomindex.get(bond.getAtom(0)) + 1, 3);
} else {
line = formatMDLInt(container.getAtomNumber(bond.getAtom(0)) + 1, 3);
line += formatMDLInt(container.getAtomNumber(bond.getAtom(1)) + 1, 3);
line = formatMDLInt(atomindex.get(bond.getAtom(0)) + 1, 3);
line += formatMDLInt(atomindex.get(bond.getAtom(1)) + 1, 3);
}
int bondType;
if (writeAromaticBondTypes.isSet() && bond.getFlag(CDKConstants.ISAROMATIC))
Expand Down Expand Up @@ -757,15 +757,15 @@ else if (Order.QUADRUPLE == bond.getOrder())
}
}

writeSgroups(container, writer);
writeSgroups(container, writer, atomindex);

// close molecule
writer.write("M END");
writer.newLine();
writer.flush();
}

private void writeSgroups(IAtomContainer container, BufferedWriter writer) throws IOException {
private void writeSgroups(IAtomContainer container, BufferedWriter writer, Map<IAtom,Integer> atomidxs) throws IOException {
List<Sgroup> sgroups = container.getProperty(CDKConstants.CTAB_SGROUPS);
if (sgroups == null)
return;
Expand Down Expand Up @@ -804,7 +804,7 @@ private void writeSgroups(IAtomContainer container, BufferedWriter writer) throw
writer.write(formatMDLInt(atoms.size(), 3));
for (IAtom atom : atoms) {
writer.write(' ');
writer.write(formatMDLInt(1+container.getAtomNumber(atom), 3));
writer.write(formatMDLInt(1+atomidxs.get(atom), 3));
}
writer.newLine();
}
Expand Down Expand Up @@ -903,7 +903,7 @@ private void writeSgroups(IAtomContainer container, BufferedWriter writer) throw
writer.write(formatMDLInt(atoms.size(), 3));
for (IAtom atom : atoms) {
writer.write(' ');
writer.write(formatMDLInt(1+container.getAtomNumber(atom), 3));
writer.write(formatMDLInt(1+atomidxs.get(atom), 3));
}
writer.newLine();
}
Expand Down

0 comments on commit d5a6914

Please sign in to comment.