Skip to content

Commit

Permalink
SMILES generator fix for allenes
Browse files Browse the repository at this point in the history
  • Loading branch information
BobHanson committed Jan 11, 2025
1 parent 520b88a commit e85d91a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
34 changes: 14 additions & 20 deletions src/org/jmol/smiles/SmilesGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,10 @@ private String getSmilesComponent(Node atom, BS bs, int mode)
allowConnectionsToOutsideWorld = ((mode
& MODE_COMP_ALLOW_OUTSIDE) != 0);
forceBrackets = ((mode & MODE_COMP_FORCE_BRACKETS) != 0);

while (true) {
if (atom == null)
atom = atoms[bs.nextSetBit(0)];

atom = checkFirstAtom(atom);

bsSelected = JmolMolecule.getBranchBitSet(atoms, atom.getIndex(),
BSUtil.copy(bs), null, -1, true, allowBioResidues);
bs.andNot(bsSelected);
Expand Down Expand Up @@ -415,10 +412,11 @@ private String getSmilesComponent(Node atom, BS bs, int mode)
atom = null;
}
}
if (atom != null)
if (atom != null) {
while ((atom = getSmilesAt(sb, atom, true,
false)) != null) {
}
}
while (!bsToDo.isEmpty() || !htRings.isEmpty()) {
Iterator<Object[]> e = htRings.values().iterator();
if (e.hasNext()) {
Expand Down Expand Up @@ -708,6 +706,7 @@ private Node getSmilesAt(SB sb, SimpleNode atom,
int atomIndex = atom.getIndex();
if (!bsToDo.get(atomIndex))
return null;
int pt = sb.length() - 1;
ptAtom++;
bsToDo.clear(atomIndex);
boolean includeHs = (atomIndex == iHypervalent
Expand Down Expand Up @@ -856,14 +855,7 @@ private Node getSmilesAt(SB sb, SimpleNode atom,
if (stereoFlag < 7 && nH == 1)
stereo[stereoFlag++] = aH;

boolean
// I guess I thought that we should not put a / before a ring number
// for a future ring, but that is not true. fixed 2022.03.12 Jmol 14.32.34
//
// deferStereo = (orderNext == 1 && sp2Atoms == null);
// if (deferStereo) {
deferStereo = false;
// }
boolean deferStereo = false;

char chBond = getBondStereochemistry(bondPrev, prevAtom);
if (strPrev != null || chBond != '\0') {
Expand Down Expand Up @@ -964,7 +956,16 @@ private Node getSmilesAt(SB sb, SimpleNode atom,
stereoFlag = 8; // no @/@@ for even cumulenes
} else {
if (nb == 3 || nb == 2 && lastIsN) {
// this is for allenes only, not general odd cumulenes
// Q is whether we have already indicated FC or C(F).
// if we have FC, and the stereo[] array starts with H,
// then we need to switch the allene stereochemistry
// note that we cannot process FC=C=C=C=CF, and neither can NCI/CADD
if (!includeHs && sb.charAt(pt) != ')'
&& ((Node) stereo[pt]).getAtomicAndIsotopeNumber() == 1) {
SimpleNode s0 = stereo[0];
stereo[0] = stereo[1];
stereo[1] = s0;
}
bonds = atomNext.getEdges();
for (int k = 0; k < bonds.length; k++) {
int index = atomNext.getBondedAtomIndex(k);
Expand All @@ -975,12 +976,6 @@ private Node getSmilesAt(SB sb, SimpleNode atom,
stereo[stereoFlag++] = atomNext;
if (stereoFlag == 4) {
alleneStereo = stereo;
if (((Node) stereo[3]).getAtomicAndIsotopeNumber() == 1) {
// if last atom is 1H, we swap.
SimpleNode n = stereo[3];
stereo[3] = stereo[2];
stereo[2] = n;
}
}
}
}
Expand Down Expand Up @@ -1383,7 +1378,6 @@ private String addStereoCheck(int level, int atomIndex, SimpleNode atom, String
int nunique = (nh == 2 ? 0 : 3);
for (int j = atom.getBondCount(); --j >= 0;) {
SimpleNode a2 = edges[j].getOtherNode(atom);
//System.out.println(level + " " + atom + " " + a2);
int i2 = a2.getIndex();
if (bsDone.get(i2) || !edges[j].isCovalent())
continue;
Expand Down
10 changes: 7 additions & 3 deletions src/org/jmol/viewer/Viewer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5146,7 +5146,7 @@ public Object setLoadFormat(boolean isSurface, String name, char type,
break;
case 'I':
case 'T':
format = g.nihResolverFormat + "/%FILE/stdinchi";
format = g.nihResolverFormat + "/%FILE/file?format=stdinchi";
break;
case 'K':
format = g.nihResolverFormat + "/%FILE/inchikey";
Expand Down Expand Up @@ -8694,10 +8694,10 @@ public String getChemicalInfo(String smiles, String info, BS bsAtoms) {
// 0 6 15 24 36 41 47 55
// 0 1 2 3 4 5
// 0123456789012345678901234567890123456789012345678901234567890
case 0: // inchi
case 0: // inchi, also stdinchi
type = 'I';
break;
case 6: // inchikey
case 6: // inchikey, also stdinchikey
type = 'K';
break;
case 15: // stdinchi
Expand Down Expand Up @@ -8734,6 +8734,10 @@ public String getChemicalInfo(String smiles, String info, BS bsAtoms) {
if (s.startsWith("InChIKey="))
s = s.substring(9);
break;
case 'I':
if (s.indexOf("\t") > 0)
s = s.substring(0, s.indexOf("\t"));
break;
case 'M':
if (s.indexOf("\n") > 0)
s = s.substring(0, s.indexOf("\n"));
Expand Down

0 comments on commit e85d91a

Please sign in to comment.