Skip to content

Commit

Permalink
Fixup, slight change in semantics so needs bounds check.
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmay committed Apr 25, 2017
1 parent effa020 commit 367f2d0
Showing 1 changed file with 12 additions and 12 deletions.
Expand Up @@ -186,7 +186,7 @@ else if ("oyl chloride".equals(funGroupToken)) {
else if ("chloro".equals(funGroupToken)) {
//If functional group hasn't had a location specified:
if (addPos < 0) {
addAtom("Cl", currentMolecule.getAtom(0), IBond.Order.SINGLE, 0);
addAtom("Cl", currentMolecule.isEmpty() ? null : currentMolecule.isEmpty() ? null : currentMolecule.getAtom(0), IBond.Order.SINGLE, 0);
} else {
addAtom("Cl", currentMolecule.getAtom(addPos), IBond.Order.SINGLE, 0);
}
Expand All @@ -195,7 +195,7 @@ else if ("chloro".equals(funGroupToken)) {
else if ("fluoro".equals(funGroupToken)) {
//If functional group hasn't had a location specified:
if (addPos < 0) {
addAtom("F", currentMolecule.getAtom(0), IBond.Order.SINGLE, 0);
addAtom("F", currentMolecule.isEmpty() ? null : currentMolecule.getAtom(0), IBond.Order.SINGLE, 0);
} else {
addAtom("F", currentMolecule.getAtom(addPos), IBond.Order.SINGLE, 0);
}
Expand All @@ -204,7 +204,7 @@ else if ("fluoro".equals(funGroupToken)) {
else if ("bromo".equals(funGroupToken)) {
//If functional group hasn't had a location specified:
if (addPos < 0) {
addAtom("Br", currentMolecule.getAtom(0), IBond.Order.SINGLE, 0);
addAtom("Br", currentMolecule.isEmpty() ? null : currentMolecule.getAtom(0), IBond.Order.SINGLE, 0);
} else {
addAtom("Br", currentMolecule.getAtom(addPos), IBond.Order.SINGLE, 0);
}
Expand All @@ -213,7 +213,7 @@ else if ("bromo".equals(funGroupToken)) {
else if ("iodo".equals(funGroupToken)) {
//If functional group hasn't had a location specified:
if (addPos < 0) {
addAtom("I", currentMolecule.getAtom(0), IBond.Order.SINGLE, 0);
addAtom("I", currentMolecule.isEmpty() ? null : currentMolecule.getAtom(0), IBond.Order.SINGLE, 0);
} else {
addAtom("I", currentMolecule.getAtom(addPos), IBond.Order.SINGLE, 0);
}
Expand All @@ -222,7 +222,7 @@ else if ("iodo".equals(funGroupToken)) {
else if ("nitro".equals(funGroupToken)) {
//If functional group hasn't had a location specified:
if (addPos < 0) {
addAtom("N", currentMolecule.getAtom(0), IBond.Order.SINGLE, 0);
addAtom("N", currentMolecule.isEmpty() ? null : currentMolecule.getAtom(0), IBond.Order.SINGLE, 0);
} else {
addAtom("N", currentMolecule.getAtom(addPos), IBond.Order.SINGLE, 0);
}
Expand All @@ -238,14 +238,14 @@ else if ("nitro".equals(funGroupToken)) {
else if ("oxo".equals(funGroupToken)) {
//If functional group hasn't had a location specified:
if (addPos < 0) {
addAtom("O", currentMolecule.getAtom(0), IBond.Order.DOUBLE, 0);
addAtom("O", currentMolecule.isEmpty() ? null : currentMolecule.getAtom(0), IBond.Order.DOUBLE, 0);
} else {
addAtom("O", currentMolecule.getAtom(addPos), IBond.Order.DOUBLE, 0);
}
}
//Nitrile
else if ("nitrile".equals(funGroupToken)) {
addAtom("N", currentMolecule.getAtom(0), IBond.Order.TRIPLE, 0);
addAtom("N", currentMolecule.isEmpty() ? null : currentMolecule.getAtom(0), IBond.Order.TRIPLE, 0);
}
//Benzene
else if ("phenyl".equals(funGroupToken)) {
Expand All @@ -262,7 +262,7 @@ else if ("phenyl".equals(funGroupToken)) {
IBond joiningBond;
//If functional group hasn't had a location specified:
if (addPos < 0) {
joiningBond = currentMolecule.getBuilder().newInstance(IBond.class, currentMolecule.getAtom(0),
joiningBond = currentMolecule.getBuilder().newInstance(IBond.class, currentMolecule.isEmpty() ? null : currentMolecule.getAtom(0),
benzene.getAtom(0));
} else {
joiningBond = currentMolecule.getBuilder().newInstance(IBond.class, currentMolecule.getAtom(addPos),
Expand All @@ -272,7 +272,7 @@ else if ("phenyl".equals(funGroupToken)) {
} else if ("amino".equals(funGroupToken)) {
//If functional group hasn't had a location specified:
if (addPos < 0) {
addAtom("N", currentMolecule.getAtom(0), IBond.Order.SINGLE, 2);
addAtom("N", currentMolecule.isEmpty() ? null : currentMolecule.getAtom(0), IBond.Order.SINGLE, 2);
} else {
addAtom("N", currentMolecule.getAtom(addPos), IBond.Order.SINGLE, 2);
}
Expand All @@ -281,14 +281,14 @@ else if ("phenyl".equals(funGroupToken)) {
else if ("alumino".equals(funGroupToken)) {
//If functional group hasn't had a location specified:
if (addPos < 0) {
addAtom("Al", currentMolecule.getAtom(0), IBond.Order.SINGLE, 2);
addAtom("Al", currentMolecule.isEmpty() ? null : currentMolecule.getAtom(0), IBond.Order.SINGLE, 2);
} else {
addAtom("Al", currentMolecule.getAtom(addPos), IBond.Order.SINGLE, 2);
}
} else if ("litho".equals(funGroupToken)) {
//If functional group hasn't had a location specified:
if (addPos < 0) {
addAtom("Li", currentMolecule.getAtom(0), IBond.Order.SINGLE, 2);
addAtom("Li", currentMolecule.isEmpty() ? null : currentMolecule.getAtom(0), IBond.Order.SINGLE, 2);
} else {
addAtom("Li", currentMolecule.getAtom(addPos), IBond.Order.SINGLE, 2);
}
Expand Down Expand Up @@ -440,7 +440,7 @@ protected IAtomContainer buildMolecule(int mainChain, List<AttachedGroup> attach

//Set the last atom here if a main chain has been built,
//if not rely on the functional group setting one of it's atoms as last
if (mainChain != 0) endOfChain = currentMolecule.getAtom(currentMolecule.getAtomCount());
if (mainChain != 0) endOfChain = currentMolecule.getAtom(currentMolecule.getAtomCount()-1);

//Add functional groups
buildFunGroups(attachedGroups);
Expand Down

0 comments on commit 367f2d0

Please sign in to comment.