use of ambit2.smarts.TopLayer in project ambit-mirror by ideaconsult.
the class SpinSplitManager method generateSpinSplitting.
SpinSplitting generateSpinSplitting(IAtom at) {
// Get simple spin splitting without JJ coupling
TopLayer tl = (TopLayer) at.getProperty(TopLayer.TLProp);
List<Integer> classes = new ArrayList<Integer>();
List<Integer> classHAtNumber = new ArrayList<Integer>();
for (int i = 0; i < tl.atoms.size(); i++) {
IAtom neighAt = tl.atoms.get(i);
int atIndex = molecule.indexOf(neighAt);
int classNum = atomClasses[atIndex];
// This code works for molecules with implicit H atoms
int numOfHAtoms = neighAt.getImplicitHydrogenCount();
if (numOfHAtoms == 0)
continue;
int k = classes.indexOf(classNum);
if (k == -1) {
classes.add(classNum);
classHAtNumber.add(numOfHAtoms);
} else {
int new_nH = numOfHAtoms + classHAtNumber.get(k);
classHAtNumber.set(k, new_nH);
}
}
SpinSplitting spinSplit = new SpinSplitting();
if (!classes.isEmpty()) {
spinSplit.numSplitLevels = classes.size();
spinSplit.splits = new int[classes.size()];
for (int i = 0; i < classHAtNumber.size(); i++) spinSplit.splits[i] = classHAtNumber.get(i) + 1;
}
return spinSplit;
}
use of ambit2.smarts.TopLayer in project ambit-mirror by ideaconsult.
the class ChemComplexityUtils method getAtomXDInfo.
/**
* @param atom
* @return array int[2] with smarts X and D primitives values for the atom
*/
public static int[] getAtomXDInfo(IAtom atom) {
int[] xd = new int[2];
xd[0] = 0;
xd[1] = 0;
List<IAtom> neighAtoms = ((TopLayer) atom.getProperty(TopLayer.TLProp)).atoms;
for (IAtom a : neighAtoms) {
xd[0]++;
if (!a.getSymbol().equals("H"))
xd[1]++;
}
Integer hci = atom.getImplicitHydrogenCount();
if (hci != null)
xd[0] += hci.intValue();
return xd;
}
use of ambit2.smarts.TopLayer in project ambit-mirror by ideaconsult.
the class Expander method determineFirstSheres.
void determineFirstSheres(SLNContainer container) {
firstSphere.clear();
int nAtom = container.getAtomCount();
int nBond = container.getBondCount();
for (int i = 0; i < nAtom; i++) {
firstSphere.put(container.getAtom(i), new TopLayer());
}
for (int i = 0; i < nBond; i++) {
IBond bond = container.getBond(i);
IAtom at0 = bond.getAtom(0);
IAtom at1 = bond.getAtom(1);
firstSphere.get(at0).atoms.add(at1);
firstSphere.get(at0).bonds.add(bond);
firstSphere.get(at1).atoms.add(at0);
firstSphere.get(at1).bonds.add(bond);
}
}
use of ambit2.smarts.TopLayer in project ambit-mirror by ideaconsult.
the class SLNHelper method nodeToString.
String nodeToString(IAtom atom) {
// System.out.println("-->nodeToString for atom: " + curSLNContainer.getAtomNumber(atom));
StringBuffer sb = new StringBuffer();
TopLayer afs = firstSphere.get(atom);
AtomSLNNode curNode = nodes.get(atom);
List<String> branches = new ArrayList<String>();
List<String> closureStrings = new ArrayList<String>();
for (int i = 0; i < afs.atoms.size(); i++) {
IAtom neighborAt = afs.atoms.get(i);
if (neighborAt == curNode.parent)
continue;
AtomSLNNode neighborNode = nodes.get(neighborAt);
if (// This node has not been registered yet
neighborNode == null) {
// Registering a new Node and a new branch
AtomSLNNode newNode = new AtomSLNNode();
newNode.atom = neighborAt;
newNode.parent = atom;
nodes.put(newNode.atom, newNode);
String bond_str = afs.bonds.get(i).toString();
String newBranch = bond_str + nodeToString(neighborAt);
branches.add(newBranch);
} else {
IBond neighborBo = afs.bonds.get(i);
// This check is needed. Otherwise the ring closure will be described twice (for both atoms of the bond)
if (ringClosures.contains(neighborBo))
continue;
ringClosures.add(neighborBo);
// Handle a new ring closure
// Set the ID of the first atom from the ring closure
// Because of the recursion approach the atoms are not yet added converted to strings
int neighID = ((SLNAtom) neighborAt).atomID;
if (// The neighbor atom does not have ID
neighID == -1) {
// A new atom ID is generated
maxAtomID++;
neighID = maxAtomID;
setAtomID((SLNAtom) neighborAt, neighID);
}
String newClosure = afs.bonds.get(i).toString() + "@" + neighID;
closureStrings.add(newClosure);
// System.out.println(" #add ring closure: atom " + curSLNContainer.getAtomNumber(atom) + " to atom "
// + curSLNContainer.getAtomNumber(neighborAt) + " with ID " + neighID);
}
}
// Add atom from the current node
sb.append(atom.toString());
// Add ring closures
for (int i = 0; i < closureStrings.size(); i++) sb.append(closureStrings.get(i));
// Add branches
if (branches.size() > 0) {
for (int i = 0; i < branches.size() - 1; i++) sb.append("(" + branches.get(i).toString() + ")");
sb.append(branches.get(branches.size() - 1).toString());
}
return (sb.toString());
}
use of ambit2.smarts.TopLayer in project ambit-mirror by ideaconsult.
the class SmartsIsomorphismTester method setQueryAtomSequence.
void setQueryAtomSequence(IQueryAtom firstAt) {
IQueryAtom firstAtom;
QuerySequenceElement seqEl;
TopLayer topLayer;
int n;
if (firstAt == null)
firstAtom = (IQueryAtom) query.getFirstAtom();
else
firstAtom = firstAt;
sequence.clear();
sequencedAtoms.clear();
sequencedBondAt1.clear();
sequencedBondAt2.clear();
// Set first sequence atom
sequencedAtoms.add(firstAtom);
seqEl = new QuerySequenceElement();
seqEl.center = firstAtom;
topLayer = (TopLayer) firstAtom.getProperty(TopLayer.TLProp);
n = topLayer.atoms.size();
seqEl.atoms = new IQueryAtom[n];
seqEl.bonds = new IQueryBond[n];
for (int i = 0; i < n; i++) {
sequencedAtoms.add((IQueryAtom) topLayer.atoms.get(i));
seqEl.atoms[i] = (IQueryAtom) topLayer.atoms.get(i);
seqEl.bonds[i] = (IQueryBond) topLayer.bonds.get(i);
addSeqBond(seqEl.center, seqEl.atoms[i]);
}
sequence.add(seqEl);
// Sequencing the entire query structure
Stack<QuerySequenceElement> stack = new Stack<QuerySequenceElement>();
stack.push(seqEl);
while (!stack.empty()) {
// curAddedAtoms.clear();
QuerySequenceElement curSeqAt = stack.pop();
for (int i = 0; i < curSeqAt.atoms.length; i++) {
topLayer = (TopLayer) curSeqAt.atoms[i].getProperty(TopLayer.TLProp);
if (topLayer.atoms.size() == 1)
// it is terminal atom and no further sequencing should be done
continue;
int[] a = getSeqAtomsInLayer(topLayer);
n = 0;
for (int k = 0; k < a.length; k++) if (a[k] == 0)
n++;
if (n > 0) {
seqEl = new QuerySequenceElement();
seqEl.center = curSeqAt.atoms[i];
seqEl.atoms = new IQueryAtom[n];
seqEl.bonds = new IQueryBond[n];
sequence.add(seqEl);
stack.add(seqEl);
}
int j = 0;
for (int k = 0; k < a.length; k++) {
if (a[k] == 0) {
seqEl.atoms[j] = (IQueryAtom) topLayer.atoms.get(k);
seqEl.bonds[j] = (IQueryBond) topLayer.bonds.get(k);
addSeqBond(seqEl.center, seqEl.atoms[j]);
sequencedAtoms.add(seqEl.atoms[j]);
// curAddedAtoms.add(seqEl.atoms[j]);
j++;
} else {
if (curSeqAt.center == topLayer.atoms.get(k))
continue;
// is already sequenced
if (getSeqBond(curSeqAt.atoms[i], topLayer.atoms.get(k)) != -1)
continue;
// topLayer.atoms.get(k) atom is already sequenced.
// Therefore sequnce element of 'bond' type is registered.
// newSeqEl is not added in the stack (this is not needed for this bond)
QuerySequenceElement newSeqEl = new QuerySequenceElement();
newSeqEl.center = null;
newSeqEl.atoms = new IQueryAtom[2];
newSeqEl.bonds = new IQueryBond[1];
newSeqEl.atoms[0] = curSeqAt.atoms[i];
newSeqEl.atoms[1] = (IQueryAtom) topLayer.atoms.get(k);
addSeqBond(newSeqEl.atoms[0], newSeqEl.atoms[1]);
newSeqEl.bonds[0] = (IQueryBond) topLayer.bonds.get(k);
sequence.add(newSeqEl);
}
}
}
}
for (int i = 0; i < sequence.size(); i++) sequence.get(i).setAtomNums(query);
}
Aggregations