use of org.openscience.cdk.interfaces.IAtom in project Smiles2Monomers by yoann-dufresne.
the class SmilesGenerator method isStartOfDoubleBond.
/**
* Says if an atom is the start of a double bond configuration
*
*@param a The atom which is the start of configuration
*@param container The atomContainer the atom is in
*@param parent The atom we came from
*@param doubleBondConfiguration The array indicating where double bond
* configurations are specified (this method ensures that there is
* actually the possibility of a double bond configuration)
*@return false=is not start of configuration, true=is
*/
private boolean isStartOfDoubleBond(IAtomContainer container, IAtom a, IAtom parent, boolean[] doubleBondConfiguration) {
// TO-DO: We make the silent assumption of unset hydrogen count equals zero hydrogen count here.
int lengthAtom = container.getConnectedAtomsCount(a) + ((a.getImplicitHydrogenCount() == CDKConstants.UNSET) ? 0 : a.getImplicitHydrogenCount());
if (lengthAtom != 3 && (lengthAtom != 2 && !a.getSymbol().equals("N"))) {
return (false);
}
List<IAtom> atoms = container.getConnectedAtomsList(a);
IAtom one = null;
IAtom two = null;
boolean doubleBond = false;
IAtom nextAtom = null;
for (IAtom atomi : atoms) {
if (atomi != parent && container.getBond(atomi, a).getOrder() == CDKConstants.BONDORDER_DOUBLE && isEndOfDoubleBond(container, atomi, a, doubleBondConfiguration)) {
doubleBond = true;
nextAtom = atomi;
}
if (atomi != nextAtom && one == null) {
one = atomi;
} else if (atomi != nextAtom && one != null) {
two = atomi;
}
}
String[] morgannumbers = MorganNumbersTools.getMorganNumbersWithElementSymbol(container);
if (one != null && ((!a.getSymbol().equals("N") && two != null && !morgannumbers[container.getAtomNumber(one)].equals(morgannumbers[container.getAtomNumber(two)]) && doubleBond && doubleBondConfiguration[container.getBondNumber(a, nextAtom)]) || (doubleBond && a.getSymbol().equals("N") && Math.abs(BondTools.giveAngleBothMethods(nextAtom, a, parent, true)) > Math.PI / 10))) {
return (true);
} else {
return (false);
}
}
use of org.openscience.cdk.interfaces.IAtom in project Smiles2Monomers by yoann-dufresne.
the class SmilesGenerator method createDFSTree.
/**
* Recursively perform a DFS search on the <code>container</code> placing
* atoms and branches in the vector <code>tree</code>.
*
*@param a the atom being visited.
*@param tree vector holding the tree.
*@param parent the atom we came from.
*@param container the AtomContainer that we are parsing.
*/
private void createDFSTree(IAtom a, List<Object> tree, IAtom parent, IAtomContainer container) {
tree.add(a);
List<IAtom> neighbours = new ArrayList<IAtom>(getCanNeigh(a, container));
neighbours.remove(parent);
IAtom next;
a.setFlag(CDKConstants.VISITED, true);
// logger.debug("Starting with DFSTree and AtomContainer of size " + container.getAtomCount());
// logger.debug("Current Atom has " + neighbours.size() + " neighbours");
Iterator<IAtom> iter = neighbours.iterator();
while (iter.hasNext()) {
next = (IAtom) iter.next();
if (!next.getFlag(CDKConstants.VISITED)) {
if (!iter.hasNext()) {
// Last neighbour therefore in this chain
createDFSTree(next, tree, a, container);
} else {
List<Object> branch = new Vector<Object>();
tree.add(branch);
// logger.debug("adding branch");
createDFSTree(next, branch, a, container);
}
} else {
// Found ring closure between next and a
// logger.debug("found ringclosure in DFTTreeCreation");
ringMarker++;
BrokenBond bond = new BrokenBond(a, next, ringMarker);
if (!brokenBonds.contains(bond)) {
brokenBonds.add(bond);
} else {
ringMarker--;
}
}
}
}
use of org.openscience.cdk.interfaces.IAtom in project Smiles2Monomers by yoann-dufresne.
the class SmilesGenerator method parseChain.
/**
* Parse a branch
*/
@SuppressWarnings("unchecked")
private void parseChain(List<Object> v, StringBuffer buffer, IAtomContainer container, IAtom parent, boolean chiral, boolean[] doubleBondConfiguration, List<IAtom> atomsInOrderOfSmiles, boolean useAromaticity) {
int positionInVector = 0;
IAtom atom;
// logger.debug("in parse chain. Size of tree: " + v.size());
for (int h = 0; h < v.size(); h++) {
Object o = v.get(h);
if (o instanceof IAtom) {
atom = (IAtom) o;
if (parent != null) {
parseBond(buffer, atom, parent, container, useAromaticity);
} else {
if (chiral && BondTools.isStereo(container, atom)) {
parent = (IAtom) ((List<?>) v.get(1)).get(0);
}
}
parseAtom(atom, buffer, container, chiral, doubleBondConfiguration, parent, atomsInOrderOfSmiles, v, useAromaticity);
/*
* The principle of making chiral smiles is quite simple, although the code is
* pretty uggly. The Atoms connected to the chiral center are put in sorted[] in the
* order they have to appear in the smiles. Then the Vector v is rearranged according
* to sorted[]
*/
if (chiral && BondTools.isStereo(container, atom) && container.getBond(parent, atom) != null) {
// logger.debug("in parseChain in isChiral");
IAtom[] sorted = null;
List<?> chiralNeighbours = container.getConnectedAtomsList(atom);
if (BondTools.isTetrahedral(container, atom, false) > 0) {
sorted = new IAtom[3];
}
if (BondTools.isTetrahedral(container, atom, false) == 1) {
if (container.getBond(parent, atom).getStereo() == IBond.Stereo.DOWN) {
for (int i = 0; i < chiralNeighbours.size(); i++) {
if (chiralNeighbours.get(i) != parent) {
if ((container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == null || container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.NONE) && BondTools.isLeft(((IAtom) chiralNeighbours.get(i)), parent, atom) && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
sorted[2] = (IAtom) chiralNeighbours.get(i);
}
if ((container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == null || container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.NONE) && !BondTools.isLeft(((IAtom) chiralNeighbours.get(i)), parent, atom) && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
sorted[1] = (IAtom) chiralNeighbours.get(i);
}
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.UP && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
sorted[0] = (IAtom) chiralNeighbours.get(i);
}
}
}
}
if (container.getBond(parent, atom).getStereo() == IBond.Stereo.UP) {
for (int i = 0; i < chiralNeighbours.size(); i++) {
if (chiralNeighbours.get(i) != parent) {
if ((container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == null || container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.NONE) && BondTools.isLeft(((IAtom) chiralNeighbours.get(i)), parent, atom) && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
sorted[1] = (IAtom) chiralNeighbours.get(i);
}
if ((container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == null || container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.NONE) && !BondTools.isLeft(((IAtom) chiralNeighbours.get(i)), parent, atom) && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
sorted[2] = (IAtom) chiralNeighbours.get(i);
}
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.DOWN && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
sorted[0] = (IAtom) chiralNeighbours.get(i);
}
}
}
}
if (container.getBond(parent, atom).getStereo() == CDKConstants.UNSET || container.getBond(parent, atom).getStereo() == IBond.Stereo.NONE) {
boolean normalBindingIsLeft = false;
for (int i = 0; i < chiralNeighbours.size(); i++) {
if (chiralNeighbours.get(i) != parent) {
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == null || container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.NONE) {
if (BondTools.isLeft(((IAtom) chiralNeighbours.get(i)), parent, atom)) {
normalBindingIsLeft = true;
break;
}
}
}
}
for (int i = 0; i < chiralNeighbours.size(); i++) {
if (chiralNeighbours.get(i) != parent) {
if (normalBindingIsLeft) {
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == null || container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.NONE) {
sorted[0] = (IAtom) chiralNeighbours.get(i);
}
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.UP) {
sorted[2] = (IAtom) chiralNeighbours.get(i);
}
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.DOWN) {
sorted[1] = (IAtom) chiralNeighbours.get(i);
}
} else {
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.UP) {
sorted[1] = (IAtom) chiralNeighbours.get(i);
}
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == null || container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.NONE) {
sorted[0] = (IAtom) chiralNeighbours.get(i);
}
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.DOWN) {
sorted[2] = (IAtom) chiralNeighbours.get(i);
}
}
}
}
}
}
if (BondTools.isTetrahedral(container, atom, false) == 2) {
if (container.getBond(parent, atom).getStereo() == IBond.Stereo.UP) {
for (int i = 0; i < chiralNeighbours.size(); i++) {
if (chiralNeighbours.get(i) != parent) {
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.DOWN && BondTools.isLeft(((IAtom) chiralNeighbours.get(i)), parent, atom) && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
sorted[1] = (IAtom) chiralNeighbours.get(i);
}
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.DOWN && !BondTools.isLeft(((IAtom) chiralNeighbours.get(i)), parent, atom) && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
sorted[2] = (IAtom) chiralNeighbours.get(i);
}
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.UP && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
sorted[0] = (IAtom) chiralNeighbours.get(i);
}
}
}
}
if (container.getBond(parent, atom).getStereo() == IBond.Stereo.DOWN) {
double angle1 = 0;
double angle2 = 0;
IAtom atom1 = null;
IAtom atom2 = null;
for (int i = 0; i < chiralNeighbours.size(); i++) {
if (chiralNeighbours.get(i) != parent) {
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.UP && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
if (angle1 == 0) {
angle1 = BondTools.giveAngle(atom, parent, (IAtom) chiralNeighbours.get(i));
atom1 = (IAtom) chiralNeighbours.get(i);
} else {
angle2 = BondTools.giveAngle(atom, parent, (IAtom) chiralNeighbours.get(i));
atom2 = (IAtom) chiralNeighbours.get(i);
}
}
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.DOWN && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
sorted[1] = (IAtom) chiralNeighbours.get(i);
}
}
}
if (angle1 < angle2) {
sorted[0] = atom2;
sorted[2] = atom1;
} else {
sorted[0] = atom1;
sorted[2] = atom2;
}
}
}
if (BondTools.isTetrahedral(container, atom, false) == 3) {
if (container.getBond(parent, atom).getStereo() == IBond.Stereo.UP) {
TreeMap<Double, Integer> hm = new TreeMap<Double, Integer>();
for (int i = 0; i < chiralNeighbours.size(); i++) {
if (chiralNeighbours.get(i) != parent && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
hm.put(new Double(BondTools.giveAngle(atom, parent, ((IAtom) chiralNeighbours.get(i)))), Integer.valueOf(i));
}
}
Object[] ohere = hm.values().toArray();
for (int i = ohere.length - 1; i > -1; i--) {
sorted[i] = ((IAtom) chiralNeighbours.get(((Integer) ohere[i]).intValue()));
}
}
if (container.getBond(parent, atom).getStereo() == null || container.getBond(parent, atom).getStereo() == IBond.Stereo.NONE) {
double angle1 = 0;
double angle2 = 0;
IAtom atom1 = null;
IAtom atom2 = null;
for (int i = 0; i < chiralNeighbours.size(); i++) {
if (chiralNeighbours.get(i) != parent) {
if ((container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == null || container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.NONE) && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
if (angle1 == 0) {
angle1 = BondTools.giveAngle(atom, parent, (IAtom) chiralNeighbours.get(i));
atom1 = (IAtom) chiralNeighbours.get(i);
} else {
angle2 = BondTools.giveAngle(atom, parent, (IAtom) chiralNeighbours.get(i));
atom2 = (IAtom) chiralNeighbours.get(i);
}
}
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.UP && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
sorted[0] = (IAtom) chiralNeighbours.get(i);
}
}
}
if (angle1 < angle2) {
sorted[1] = atom2;
sorted[2] = atom1;
} else {
sorted[1] = atom1;
sorted[2] = atom2;
}
}
}
if (BondTools.isTetrahedral(container, atom, false) == 4) {
if (container.getBond(parent, atom).getStereo() == IBond.Stereo.DOWN) {
TreeMap<Double, Integer> hm = new TreeMap<Double, Integer>();
for (int i = 0; i < chiralNeighbours.size(); i++) {
if (chiralNeighbours.get(i) != parent && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
hm.put(new Double(BondTools.giveAngle(atom, parent, ((IAtom) chiralNeighbours.get(i)))), Integer.valueOf(i));
}
}
Object[] ohere = hm.values().toArray();
for (int i = ohere.length - 1; i > -1; i--) {
sorted[i] = ((IAtom) chiralNeighbours.get(((Integer) ohere[i]).intValue()));
}
}
if (container.getBond(parent, atom).getStereo() == null || container.getBond(parent, atom).getStereo() == IBond.Stereo.NONE) {
double angle1 = 0;
double angle2 = 0;
IAtom atom1 = null;
IAtom atom2 = null;
for (int i = 0; i < chiralNeighbours.size(); i++) {
if (chiralNeighbours.get(i) != parent) {
if ((container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == null || container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.NONE) && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
if (angle1 == 0) {
angle1 = BondTools.giveAngle(atom, parent, (IAtom) chiralNeighbours.get(i));
atom1 = (IAtom) chiralNeighbours.get(i);
} else {
angle2 = BondTools.giveAngle(atom, parent, (IAtom) chiralNeighbours.get(i));
atom2 = (IAtom) chiralNeighbours.get(i);
}
}
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.DOWN && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
sorted[2] = (IAtom) chiralNeighbours.get(i);
}
}
}
if (angle1 < angle2) {
sorted[1] = atom2;
sorted[0] = atom1;
} else {
sorted[1] = atom1;
sorted[0] = atom2;
}
}
}
if (BondTools.isTetrahedral(container, atom, false) == 5) {
if (container.getBond(parent, atom).getStereo() == IBond.Stereo.DOWN) {
for (int i = 0; i < chiralNeighbours.size(); i++) {
if (chiralNeighbours.get(i) != parent) {
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.UP) {
sorted[0] = (IAtom) chiralNeighbours.get(i);
}
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == null || container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.NONE) {
sorted[2] = (IAtom) chiralNeighbours.get(i);
}
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.DOWN) {
sorted[1] = (IAtom) chiralNeighbours.get(i);
}
}
}
}
if (container.getBond(parent, atom).getStereo() == IBond.Stereo.UP) {
for (int i = 0; i < chiralNeighbours.size(); i++) {
if (chiralNeighbours.get(i) != parent) {
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.DOWN && BondTools.isLeft(((IAtom) chiralNeighbours.get(i)), parent, atom) && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
sorted[0] = (IAtom) chiralNeighbours.get(i);
}
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.DOWN && !BondTools.isLeft(((IAtom) chiralNeighbours.get(i)), parent, atom) && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
sorted[2] = (IAtom) chiralNeighbours.get(i);
}
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == null || container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.NONE) {
sorted[1] = (IAtom) chiralNeighbours.get(i);
}
}
}
}
if (container.getBond(parent, atom).getStereo() == CDKConstants.UNSET || container.getBond(parent, atom).getStereo() == IBond.Stereo.NONE) {
for (int i = 0; i < chiralNeighbours.size(); i++) {
if (chiralNeighbours.get(i) != parent) {
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.DOWN && BondTools.isLeft(((IAtom) chiralNeighbours.get(i)), parent, atom) && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
sorted[0] = (IAtom) chiralNeighbours.get(i);
}
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.DOWN && !BondTools.isLeft(((IAtom) chiralNeighbours.get(i)), parent, atom) && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
sorted[2] = (IAtom) chiralNeighbours.get(i);
}
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.UP) {
sorted[1] = (IAtom) chiralNeighbours.get(i);
}
}
}
}
}
if (BondTools.isTetrahedral(container, atom, false) == 6) {
if (container.getBond(parent, atom).getStereo() == IBond.Stereo.UP) {
for (int i = 0; i < chiralNeighbours.size(); i++) {
if (chiralNeighbours.get(i) != parent) {
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.UP) {
sorted[0] = (IAtom) chiralNeighbours.get(i);
}
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == null || container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.NONE) {
sorted[2] = (IAtom) chiralNeighbours.get(i);
}
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.DOWN) {
sorted[1] = (IAtom) chiralNeighbours.get(i);
}
}
}
}
if (container.getBond(parent, atom).getStereo() == IBond.Stereo.DOWN) {
for (int i = 0; i < chiralNeighbours.size(); i++) {
if (chiralNeighbours.get(i) != parent) {
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.UP && BondTools.isLeft(((IAtom) chiralNeighbours.get(i)), parent, atom) && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
sorted[2] = (IAtom) chiralNeighbours.get(i);
}
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.UP && !BondTools.isLeft(((IAtom) chiralNeighbours.get(i)), parent, atom) && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
sorted[0] = (IAtom) chiralNeighbours.get(i);
}
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == null || container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.NONE) {
sorted[1] = (IAtom) chiralNeighbours.get(i);
}
}
}
}
if (container.getBond(parent, atom).getStereo() == CDKConstants.UNSET || container.getBond(parent, atom).getStereo() == IBond.Stereo.NONE) {
for (int i = 0; i < chiralNeighbours.size(); i++) {
if (chiralNeighbours.get(i) != parent) {
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.UP && BondTools.isLeft(((IAtom) chiralNeighbours.get(i)), parent, atom) && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
sorted[2] = (IAtom) chiralNeighbours.get(i);
}
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.UP && !BondTools.isLeft(((IAtom) chiralNeighbours.get(i)), parent, atom) && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
sorted[0] = (IAtom) chiralNeighbours.get(i);
}
if (container.getBond((IAtom) chiralNeighbours.get(i), atom).getStereo() == IBond.Stereo.DOWN) {
sorted[1] = (IAtom) chiralNeighbours.get(i);
}
}
}
}
}
if (BondTools.isSquarePlanar(container, atom)) {
sorted = new IAtom[3];
// This produces a U=SP1 order in every case
TreeMap<Double, Integer> hm = new TreeMap<Double, Integer>();
for (int i = 0; i < chiralNeighbours.size(); i++) {
if (chiralNeighbours.get(i) != parent && !isBondBroken((IAtom) chiralNeighbours.get(i), atom)) {
hm.put(new Double(BondTools.giveAngle(atom, parent, ((IAtom) chiralNeighbours.get(i)))), Integer.valueOf(i));
}
}
Object[] ohere = hm.values().toArray();
for (int i = 0; i < ohere.length; i++) {
sorted[i] = ((IAtom) chiralNeighbours.get(((Integer) ohere[i]).intValue()));
}
}
if (BondTools.isTrigonalBipyramidalOrOctahedral(container, atom) != 0) {
sorted = new IAtom[container.getConnectedAtomsCount(atom) - 1];
TreeMap<Double, Integer> hm = new TreeMap<Double, Integer>();
if (container.getBond(parent, atom).getStereo() == IBond.Stereo.UP) {
for (int i = 0; i < chiralNeighbours.size(); i++) {
if (container.getBond(atom, (IAtom) chiralNeighbours.get(i)).getStereo() == null || container.getBond(atom, (IAtom) chiralNeighbours.get(i)).getStereo() == IBond.Stereo.NONE) {
hm.put(new Double(BondTools.giveAngle(atom, parent, ((IAtom) chiralNeighbours.get(i)))), Integer.valueOf(i));
}
if (container.getBond(atom, (IAtom) chiralNeighbours.get(i)).getStereo() == IBond.Stereo.DOWN) {
sorted[sorted.length - 1] = (IAtom) chiralNeighbours.get(i);
}
}
Object[] ohere = hm.values().toArray();
for (int i = 0; i < ohere.length; i++) {
sorted[i] = ((IAtom) chiralNeighbours.get(((Integer) ohere[i]).intValue()));
}
}
if (container.getBond(parent, atom).getStereo() == IBond.Stereo.DOWN) {
for (int i = 0; i < chiralNeighbours.size(); i++) {
if (container.getBond(atom, (IAtom) chiralNeighbours.get(i)).getStereo() == null || container.getBond(atom, (IAtom) chiralNeighbours.get(i)).getStereo() == IBond.Stereo.NONE) {
hm.put(new Double(BondTools.giveAngle(atom, parent, ((IAtom) chiralNeighbours.get(i)))), Integer.valueOf(i));
}
if (container.getBond(atom, (IAtom) chiralNeighbours.get(i)).getStereo() == IBond.Stereo.UP) {
sorted[sorted.length - 1] = (IAtom) chiralNeighbours.get(i);
}
}
Object[] ohere = hm.values().toArray();
for (int i = 0; i < ohere.length; i++) {
sorted[i] = ((IAtom) chiralNeighbours.get(((Integer) ohere[i]).intValue()));
}
}
if (container.getBond(parent, atom).getStereo() == null || container.getBond(parent, atom).getStereo() == IBond.Stereo.NONE) {
for (int i = 0; i < chiralNeighbours.size(); i++) {
if (chiralNeighbours.get(i) != parent) {
if (container.getBond(atom, (IAtom) chiralNeighbours.get(i)).getStereo() == null || container.getBond(atom, (IAtom) chiralNeighbours.get(i)).getStereo() == IBond.Stereo.NONE) {
hm.put(new Double((BondTools.giveAngleFromMiddle(atom, parent, ((IAtom) chiralNeighbours.get(i))))), Integer.valueOf(i));
}
if (container.getBond(atom, (IAtom) chiralNeighbours.get(i)).getStereo() == IBond.Stereo.UP) {
sorted[0] = (IAtom) chiralNeighbours.get(i);
}
if (container.getBond(atom, (IAtom) chiralNeighbours.get(i)).getStereo() == IBond.Stereo.DOWN) {
sorted[sorted.length - 2] = (IAtom) chiralNeighbours.get(i);
}
}
}
Object[] ohere = hm.values().toArray();
sorted[sorted.length - 1] = ((IAtom) chiralNeighbours.get(((Integer) ohere[ohere.length - 1]).intValue()));
if (ohere.length == 2) {
sorted[sorted.length - 3] = ((IAtom) chiralNeighbours.get(((Integer) ohere[0]).intValue()));
if (BondTools.giveAngleFromMiddle(atom, parent, ((IAtom) chiralNeighbours.get(((Integer) ohere[1]).intValue()))) < 0) {
IAtom dummy = sorted[sorted.length - 2];
sorted[sorted.length - 2] = sorted[0];
sorted[0] = dummy;
}
}
if (ohere.length == 3) {
sorted[sorted.length - 3] = sorted[sorted.length - 2];
sorted[sorted.length - 2] = ((IAtom) chiralNeighbours.get(((Integer) ohere[ohere.length - 2]).intValue()));
sorted[sorted.length - 4] = ((IAtom) chiralNeighbours.get(((Integer) ohere[ohere.length - 3]).intValue()));
}
}
}
// This builds an onew[] containing the objects after the center of the chirality in the order given by sorted[]
if (sorted != null) {
int numberOfAtoms = 3;
if (BondTools.isTrigonalBipyramidalOrOctahedral(container, atom) != 0) {
numberOfAtoms = container.getConnectedAtomsCount(atom) - 1;
}
Object[] omy = new Object[numberOfAtoms];
Object[] onew = new Object[numberOfAtoms];
for (int k = getRingOpenings(atom, null).size(); k < numberOfAtoms; k++) {
if (positionInVector + 1 + k - getRingOpenings(atom, null).size() < v.size()) {
omy[k] = v.get(positionInVector + 1 + k - getRingOpenings(atom, null).size());
}
}
for (int k = 0; k < sorted.length; k++) {
if (sorted[k] != null) {
for (int m = 0; m < omy.length; m++) {
if (omy[m] instanceof IAtom) {
if (omy[m] == sorted[k]) {
onew[k] = omy[m];
}
} else {
if (omy[m] == null) {
onew[k] = null;
} else {
if (((List<?>) omy[m]).get(0) == sorted[k]) {
onew[k] = omy[m];
}
}
}
}
} else {
onew[k] = null;
}
}
// This is a workaround for 3624.MOL.2 I don't have a better solution currently
boolean doubleentry = false;
for (int m = 0; m < onew.length; m++) {
for (int k = 0; k < onew.length; k++) {
if (m != k && onew[k] == onew[m]) {
doubleentry = true;
}
}
}
if (!doubleentry) {
// Make sure that the first atom in onew is the first one in the original smiles order. This is important to have a canonical smiles.
if (positionInVector + 1 < v.size()) {
Object atomAfterCenterInOriginalSmiles = v.get(positionInVector + 1);
int l = 0;
while (onew[0] != atomAfterCenterInOriginalSmiles) {
Object placeholder = onew[onew.length - 1];
for (int k = onew.length - 2; k > -1; k--) {
onew[k + 1] = onew[k];
}
onew[0] = placeholder;
l++;
if (l > onew.length) {
break;
}
}
}
// This cares about ring openings. Here the ring closure (represendted by a figure) must be the first atom. In onew the closure is null.
if (getRingOpenings(atom, null).size() > 0) {
int l = 0;
while (onew[0] != null) {
Object placeholder = onew[0];
for (int k = 1; k < onew.length; k++) {
onew[k - 1] = onew[k];
}
onew[onew.length - 1] = placeholder;
l++;
if (l > onew.length) {
break;
}
}
}
// The last in onew is a vector: This means we need to exchange the rest of the original smiles with the rest of this vector.
if (onew[numberOfAtoms - 1] instanceof List) {
for (int i = 0; i < numberOfAtoms; i++) {
if (onew[i] instanceof IAtom) {
List<Object> vtemp = new Vector<Object>();
vtemp.add(onew[i]);
for (int k = positionInVector + 1 + numberOfAtoms; k < v.size(); k++) {
vtemp.add(v.get(k));
}
onew[i] = vtemp;
for (int k = v.size() - 1; k > positionInVector + 1 + numberOfAtoms - 1; k--) {
v.remove(k);
}
for (int k = 1; k < ((List<?>) onew[numberOfAtoms - 1]).size(); k++) {
v.add(((List<?>) onew[numberOfAtoms - 1]).get(k));
}
onew[numberOfAtoms - 1] = ((List<?>) onew[numberOfAtoms - 1]).get(0);
break;
}
}
}
// Put the onew objects in the original Vector
int k = 0;
for (int m = 0; m < onew.length; m++) {
if (onew[m] != null) {
v.set(positionInVector + 1 + k, onew[m]);
k++;
}
}
}
}
}
parent = atom;
} else {
// Have Vector
// logger.debug("in parseChain after else");
boolean brackets = true;
List<IAtom> result = new Vector<IAtom>();
addAtoms((List<?>) o, result);
IAtom prevAtom;
/*
* Got to find last atom that was processed.
* This is to check the relative position of the current atom/chain with respect to its parent
*/
prevAtom = (IAtom) ((Vector<IAtom>) atomsInOrderOfSmiles).lastElement();
int maxConnectedBondCount = 4;
/**
* If the parent atom of this new chain is the very first atom in the SMILES string and this chain is placed
* immediately after the parent atom then the max connected bond count for the parent should be 3 instead of 4.
*/
if (atomsInOrderOfSmiles.indexOf(parent) == 0 && prevAtom == parent) {
maxConnectedBondCount = 3;
}
if (isRingOpening(parent, result) && container.getConnectedBondsCount(parent) < maxConnectedBondCount) {
brackets = false;
}
if (brackets) {
buffer.append('(');
}
parseChain((List<Object>) o, buffer, container, parent, chiral, doubleBondConfiguration, atomsInOrderOfSmiles, useAromaticity);
if (brackets) {
buffer.append(')');
}
}
positionInVector++;
// logger.debug("in parseChain after positionVector++");
}
}
use of org.openscience.cdk.interfaces.IAtom in project Smiles2Monomers by yoann-dufresne.
the class SmilesGenerator method isEndOfDoubleBond.
/**
* Says if an atom is the end of a double bond configuration
*
*@param atom The atom which is the end of configuration
*@param container The atomContainer the atom is in
*@param parent The atom we came from
*@param doubleBondConfiguration The array indicating where double bond
* configurations are specified (this method ensures that there is
* actually the possibility of a double bond configuration)
*@return false=is not end of configuration, true=is
*/
private boolean isEndOfDoubleBond(IAtomContainer container, IAtom atom, IAtom parent, boolean[] doubleBondConfiguration) {
if (container.getBondNumber(atom, parent) == -1 || doubleBondConfiguration.length <= container.getBondNumber(atom, parent) || !doubleBondConfiguration[container.getBondNumber(atom, parent)]) {
return false;
}
// TO-DO: We make the silent assumption of unset hydrogen count equals zero hydrogen count here.
int lengthAtom = container.getConnectedAtomsCount(atom) + ((atom.getImplicitHydrogenCount() == CDKConstants.UNSET) ? 0 : atom.getImplicitHydrogenCount());
// TO-DO: We make the silent assumption of unset hydrogen count equals zero hydrogen count here.
int lengthParent = container.getConnectedAtomsCount(parent) + ((parent.getImplicitHydrogenCount() == CDKConstants.UNSET) ? 0 : parent.getImplicitHydrogenCount());
if (container.getBond(atom, parent) != null) {
if (container.getBond(atom, parent).getOrder() == CDKConstants.BONDORDER_DOUBLE && (lengthAtom == 3 || (lengthAtom == 2 && atom.getSymbol().equals("N"))) && (lengthParent == 3 || (lengthParent == 2 && parent.getSymbol().equals("N")))) {
List<IAtom> atoms = container.getConnectedAtomsList(atom);
IAtom one = null;
IAtom two = null;
IAtom atomi = null;
for (int i = 0; i < atoms.size(); i++) {
atomi = (IAtom) container.getAtom(i);
if (atomi != parent && one == null) {
one = atomi;
} else if (atomi != parent && one != null) {
two = atomi;
}
}
String[] morgannumbers = MorganNumbersTools.getMorganNumbersWithElementSymbol(container);
if ((one != null && two == null && atom.getSymbol().equals("N") && Math.abs(BondTools.giveAngleBothMethods(parent, atom, one, true)) > Math.PI / 10) || (!atom.getSymbol().equals("N") && one != null && two != null && !morgannumbers[container.getAtomNumber(one)].equals(morgannumbers[container.getAtomNumber(two)]))) {
return (true);
} else {
return (false);
}
}
}
return (false);
}
use of org.openscience.cdk.interfaces.IAtom in project Smiles2Monomers by yoann-dufresne.
the class BlocsTests method setUp.
@Before
public void setUp() throws Exception {
this.sc = SmilesConverter.conv;
// String smiles = "C(C(=O)O)C(=O)N";
IAtom a1;
IAtom a2;
a1 = new Atom("C");
a1.setFlag(CDKConstants.ISAROMATIC, true);
a2 = new Atom("N");
a2.setFlag(CDKConstants.ISAROMATIC, true);
// NC
this.ext1 = new Extension(new Bond(a1, a2, Order.SINGLE));
a2 = new Atom("O");
// NC=O
this.ext2 = new Extension(new Bond(a1, a2, Order.DOUBLE));
a2 = new Atom("C");
a2.setFlag(CDKConstants.ISAROMATIC, true);
// NC(C)=O
this.ext3 = new Extension(new Bond(a1, a2, Order.SINGLE));
a1 = new Atom("C");
a1.setFlag(CDKConstants.ISAROMATIC, true);
// NC(CC)=O
this.ext4 = new Extension(new Bond(a1, a2, Order.SINGLE));
a2 = new Atom("C");
a2.setFlag(CDKConstants.ISAROMATIC, true);
// NC(CCC)=O
this.ext5 = new Extension(new Bond(a1, a2, Order.SINGLE));
a1 = new Atom("C");
a1.setFlag(CDKConstants.ISAROMATIC, true);
a2 = new Atom("N");
a2.setFlag(CDKConstants.ISAROMATIC, true);
// N1C(CCC1)=O
this.ext6 = new Extension(new Bond(a1, a2, Order.SINGLE));
// NC
this.blc1 = new Chain(null, ext1, -1, -1);
// NC=O
this.blc2 = new Chain(blc1, ext2, -1, 0);
// NC(C)=O
this.blc3 = new Chain(blc2, ext3, 0, -1);
// NC(CC)=O
this.blc4 = new Chain(blc3, ext4, 3, -1);
// NC(CCC)=O
this.blc5 = new Chain(blc4, ext5, 4, -1);
// N1C(CC1)=O
this.blc6 = new Chain(blc5, ext6, 5, 1);
}
Aggregations