use of ambit2.sln.SLNAtom in project ambit-mirror by ideaconsult.
the class SLN2ChemObject method slnContainerToQueryAtomContainer.
public IQueryAtomContainer slnContainerToQueryAtomContainer(SLNContainer slnContainer) {
clearAllErrorsAndWarnings();
IQueryAtomContainer container = new QueryAtomContainer(SilentChemObjectBuilder.getInstance());
Map<SLNAtom, IQueryAtom> convertedAtoms = new HashMap<SLNAtom, IQueryAtom>();
for (int i = 0; i < slnContainer.getAtomCount(); i++) {
SLNAtom slnAtom = (SLNAtom) slnContainer.getAtom(i);
IQueryAtom atom = slnAtomToQueryAtom(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);
IQueryBond bond = slnBondToQueryBond(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);
}
return container;
}
use of ambit2.sln.SLNAtom in project ambit-mirror by ideaconsult.
the class SLN2ChemObject method atomContainerToSLNContainer.
public SLNContainer atomContainerToSLNContainer(IAtomContainer container) {
clearAllErrorsAndWarnings();
SLNContainer slnContainer = new SLNContainer(null);
Map<IAtom, SLNAtom> convertedAtoms = new HashMap<IAtom, SLNAtom>();
for (int i = 0; i < container.getAtomCount(); i++) {
IAtom atom = container.getAtom(i);
SLNAtom slnAtom = atomToSLNAtom(atom);
if (currentConversionWarning != null)
conversionWarnings.add(currentConversionWarning + " for atom: " + (i + 1));
if (slnAtom == null) {
conversionErrors.add(currentConversionError + " for atom: " + (i + 1));
continue;
}
slnContainer.addAtom(slnAtom);
convertedAtoms.put(atom, slnAtom);
}
for (int i = 0; i < container.getBondCount(); i++) {
IBond bond = container.getBond(i);
SLNBond slnBond = bondToSLNBond(bond);
if (currentConversionWarning != null)
conversionWarnings.add(currentConversionWarning + " for bond: " + (i + 1));
if (slnBond == null) {
conversionErrors.add(currentConversionError + " for bond: " + (i + 1));
continue;
}
SLNAtom[] newAtoms = new SLNAtom[2];
newAtoms[0] = convertedAtoms.get(bond.getAtom(0));
newAtoms[1] = convertedAtoms.get(bond.getAtom(1));
if (newAtoms[0] == null || newAtoms[1] == null) {
conversionErrors.add("One of the atoms for bond: " + (i + 1) + " is not converted");
// one of the atoms is not converted
continue;
}
slnBond.setAtoms(newAtoms);
slnContainer.addBond(slnBond);
}
return slnContainer;
}
use of ambit2.sln.SLNAtom in project ambit-mirror by ideaconsult.
the class SLN2ChemObject method atomToSLNAtom.
public SLNAtom atomToSLNAtom(IAtom atom) {
currentConversionError = null;
currentConversionWarning = null;
if (atom == null) {
currentConversionError = "Atom is null";
return null;
}
SLNAtom slnAt = new SLNAtom(builder);
String atomName = atom.getSymbol();
for (int i = 0; i < SLNConst.elSymbols.length; i++) if (atomName.equals(SLNConst.elSymbols[i])) {
slnAt.atomType = i;
break;
}
slnAt.atomName = atomName;
if (atom.getImplicitHydrogenCount() != null)
slnAt.numHAtom = atom.getImplicitHydrogenCount();
return slnAt;
}
use of ambit2.sln.SLNAtom in project ambit-mirror by ideaconsult.
the class SLN2ChemObject method slnAtomToQueryAtom.
public IQueryAtom slnAtomToQueryAtom(SLNAtom slnAt) {
currentConversionError = null;
currentConversionWarning = null;
if (slnAt == null) {
currentConversionError = "SNLAtom is null";
return null;
}
if (slnAt.atomType == 0) {
if (slnAt.atomExpression == null || slnAt.atomExpression.tokens.isEmpty()) {
if (slnAt.numHAtom == 0)
return new AnyAtom(SilentChemObjectBuilder.getInstance());
}
// Handle Any atom as an expression
// slnAt.numHAtom > 0 info is added into the expression
SmartsAtomExpression atExpr = slnAtomToSmartsAtomExpression(slnAt);
return atExpr;
}
// slnAt.atomType > 0
if (slnAt.atomType < SLNConst.GlobalDictOffseet) {
if (slnAt.atomType < SLNConst.elSymbols.length) {
if (slnAt.atomExpression == null || slnAt.atomExpression.tokens.isEmpty()) {
if (slnAt.numHAtom == 0) {
AliphaticSymbolQueryAtom atom = new AliphaticSymbolQueryAtom(SilentChemObjectBuilder.getInstance());
String symb = SLNConst.elSymbols[slnAt.atomType];
atom.setSymbol(symb);
atom.setAtomicNumber(PeriodicTable.getAtomicNumber(symb));
return atom;
} else {
// Since there are H atoms they define an expression
// slnAt.numHAtom > 0 info is added into the expression
}
}
// Create an expression
SmartsAtomExpression atExpr = slnAtomToSmartsAtomExpression(slnAt);
return atExpr;
} else {
// TODO
return null;
}
} else {
// TODO
return null;
}
}
use of ambit2.sln.SLNAtom in project ambit-mirror by ideaconsult.
the class SLN2ChemObject method queryAtomToSLNAtom.
public SLNAtom queryAtomToSLNAtom(IQueryAtom queryAtom) {
currentConversionError = null;
currentConversionWarning = null;
if (queryAtom == null) {
currentConversionError = "Atom is null";
return null;
}
if (queryAtom instanceof SmartsAtomExpression) {
// TODO
}
boolean FlagKnownAtomType = false;
SLNAtom slnAt = new SLNAtom(builder);
if (queryAtom instanceof AnyAtom) {
slnAt.atomType = 0;
slnAt.atomName = "Any";
FlagKnownAtomType = true;
}
if (FlagKnownAtomType)
return slnAt;
else
return null;
/*
* SLNAtom slnAt = new SLNAtom(builder);
String atomName = atom.getSymbol();
for (int i = 0; i < SLNConst.elSymbols.length; i++)
if (atomName.equals(SLNConst.elSymbols[i]))
{
slnAt.atomType = i;
break;
}
slnAt.atomName = atomName;
if (a instanceof AliphaticSymbolQueryAtom)
return (a.getSymbol());
if (a instanceof AromaticSymbolQueryAtom)
return (a.getSymbol().toLowerCase());
if (a instanceof AliphaticAtom)
return ("A");
if (a instanceof AromaticAtom)
return ("a");
*/
}
Aggregations