use of ambit2.sln.SLNContainer 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.SLNContainer 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.SLNContainer 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.SLNContainer in project ambit-mirror by ideaconsult.
the class SLN2SMARTS method slnToSmiles.
public String slnToSmiles(String sln) throws Exception {
reset();
SLNContainer container = slnParser.parse(sln);
String parserErr = slnParser.getErrorMessages();
if (!parserErr.equals("")) {
conversionErrors.add(parserErr);
return null;
}
IAtomContainer mol = slnConverter.slnContainerToAtomContainer(container);
String smiles = SmartsHelper.moleculeToSMILES(mol, false);
conversionErrors.addAll(slnConverter.getConversionErrors());
conversionWarnings.addAll(slnConverter.getConversionWarnings());
return smiles;
}
use of ambit2.sln.SLNContainer in project ambit-mirror by ideaconsult.
the class SLN2SMARTS method slnToSmarts.
public String slnToSmarts(String sln) {
reset();
SLNContainer container = slnParser.parse(sln);
String parserErr = slnParser.getErrorMessages();
if (!parserErr.equals("")) {
conversionErrors.add(parserErr);
return null;
}
IQueryAtomContainer query = slnConverter.slnContainerToQueryAtomContainer(container);
String smarts = smartsHelper.toSmarts(query);
conversionErrors.addAll(slnConverter.getConversionErrors());
conversionWarnings.addAll(slnConverter.getConversionWarnings());
return smarts;
}
Aggregations