use of ambit2.sln.SLNAtom in project ambit-mirror by ideaconsult.
the class SLN2ChemObject method slnContainerToAtomContainer.
public IAtomContainer slnContainerToAtomContainer(SLNContainer slnContainer) {
clearAllErrorsAndWarnings();
IAtomContainer container = new AtomContainer();
Map<SLNAtom, IAtom> convertedAtoms = new HashMap<SLNAtom, IAtom>();
for (int i = 0; i < slnContainer.getAtomCount(); i++) {
SLNAtom slnAtom = (SLNAtom) slnContainer.getAtom(i);
IAtom atom = slnAtomToAtom(slnAtom);
if (currentConversionWarning != null)
conversionWarnings.add(currentConversionWarning + " for atom: " + (i + 1));
if (atom == null) {
conversionErrors.add(currentConversionError + " for atom: " + (i + 1));
continue;
}
container.addAtom(atom);
convertedAtoms.put(slnAtom, atom);
}
for (int i = 0; i < slnContainer.getBondCount(); i++) {
SLNBond slnBbond = (SLNBond) slnContainer.getBond(i);
IBond bond = slnBondToBond(slnBbond);
if (currentConversionWarning != null)
conversionWarnings.add(currentConversionWarning + " for bond: " + (i + 1));
if (bond == null) {
conversionErrors.add(currentConversionError + " for bond: " + (i + 1));
continue;
}
IAtom[] newAtoms = new IAtom[2];
newAtoms[0] = convertedAtoms.get(slnBbond.getAtom(0));
newAtoms[1] = convertedAtoms.get(slnBbond.getAtom(1));
if (newAtoms[0] == null || newAtoms[1] == null)
// one of the atoms is not converted
continue;
bond.setAtoms(newAtoms);
container.addBond(bond);
}
try {
processMolecule(container);
} catch (Exception x) {
conversionErrors.add(x.getMessage());
}
return container;
}
use of ambit2.sln.SLNAtom in project ambit-mirror by ideaconsult.
the class Expander method handleBond.
public void handleBond(IBond bond) {
SLNBond bo = (SLNBond) bond;
SLNBond newBo = bo.clone();
IAtom at0 = bo.getAtom(0);
IAtom at1 = bo.getAtom(1);
int conectionInd0 = getConnectionIndexOfTheBond(bond, at0);
int conectionInd1 = getConnectionIndexOfTheBond(bond, at1);
// TODO improved valencePos index handling taking into account attribute v if present
int valencePos0Index = conectionInd0;
int valencePos1Index = conectionInd1;
Object newObj0 = oldToNewAtoms.get(at0);
Object newObj1 = oldToNewAtoms.get(at1);
IAtom newAt0 = getNewAtomWhichIsValenceConection(valencePos0Index, newObj0, (SLNAtom) at0);
IAtom newAt1 = getNewAtomWhichIsValenceConection(valencePos1Index, newObj1, (SLNAtom) at1);
newBo.setAtoms(new IAtom[] { newAt0, newAt1 });
expContainer.addBond(newBo);
}
use of ambit2.sln.SLNAtom in project ambit-mirror by ideaconsult.
the class Expander method expandMacroAtomDictionaryObject.
public List<IAtom> expandMacroAtomDictionaryObject(MacroAtomDictionaryObject maDO) {
// Clone all atoms from maDO and add to the expanded container
List<IAtom> newAtoms = new ArrayList<IAtom>();
for (int i = 0; i < maDO.container.getAtomCount(); i++) {
SLNAtom at = (SLNAtom) maDO.container.getAtom(i);
SLNAtom newAt = at.clone();
expContainer.addAtom(newAt);
newAtoms.add(newAt);
}
// Also, clone all bonds from maDO and add to the expanded container
for (int i = 0; i < maDO.container.getBondCount(); i++) {
SLNBond bo = (SLNBond) maDO.container.getBond(i);
SLNBond newBo = bo.clone();
int index0 = maDO.container.indexOf(bo.getAtom(0));
int index1 = maDO.container.indexOf(bo.getAtom(1));
newBo.setAtoms(new IAtom[] { newAtoms.get(index0), newAtoms.get(index1) });
expContainer.addBond(newBo);
}
return newAtoms;
}
use of ambit2.sln.SLNAtom 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.sln.SLNAtom in project ambit-mirror by ideaconsult.
the class SLN2ChemObject method slnAtomToAtom.
public IAtom slnAtomToAtom(SLNAtom slnAt) {
currentConversionError = null;
currentConversionWarning = null;
if (slnAt == null) {
currentConversionError = "SNLAtom is null";
return null;
}
if ((slnAt.atomType > 0) && (slnAt.atomType < SLNConst.GlobalDictOffseet)) {
if (slnAt.atomType < SLNConst.elSymbols.length) {
IAtom atom = new Atom();
atom.setSymbol(SLNConst.elSymbols[slnAt.atomType]);
atom.setAtomicNumber(PeriodicTable.getAtomicNumber(SLNConst.elSymbols[slnAt.atomType]));
atom.setImplicitHydrogenCount(slnAt.numHAtom);
if (slnAt.atomExpression != null) {
Integer charge = extractFormalCharge(slnAt.atomExpression);
if (charge != null)
if (charge != 0)
atom.setFormalCharge(charge);
// TODO isotope
}
return atom;
} else {
currentConversionError = "SNLAtom type is incorrect: " + slnAt.atomType;
return null;
}
} else {
currentConversionError = "SNLAtom type is not defined";
return null;
}
}
Aggregations