use of ambit2.sln.SLNBond in project ambit-mirror by ideaconsult.
the class SLN2ChemObject method slnBondToQueryBond.
/*
* Converts only the bond type/expression info
* connected atoms info is not handled
*/
public IQueryBond slnBondToQueryBond(SLNBond slnBo) {
currentConversionError = null;
currentConversionWarning = null;
if (slnBo == null) {
currentConversionError = "Bond is null";
return null;
}
if (slnBo.bondType == 0) {
if (slnBo.bondExpression == null)
return new AnyOrderQueryBond(SilentChemObjectBuilder.getInstance());
// TODO handle bond expression
} else {
if (slnBo.bondExpression == null) {
IQueryBond bond = null;
switch(slnBo.bondType) {
case 1:
if (conversionConfig.FlagSLNSingleBondToSingleOrAromaticBond)
bond = new SingleOrAromaticBond(SilentChemObjectBuilder.getInstance());
else if (conversionConfig.FlagSupportSingleBondAromaticityNotSpecified)
bond = new SingleBondAromaticityNotSpecified(SilentChemObjectBuilder.getInstance());
else
bond = new SingleNonAromaticBond(SilentChemObjectBuilder.getInstance());
break;
case 2:
if (conversionConfig.FlagSupportDoubleBondAromaticityNotSpecified)
bond = new DoubleBondAromaticityNotSpecified(SilentChemObjectBuilder.getInstance());
else
bond = new DoubleNonAromaticBond(SilentChemObjectBuilder.getInstance());
break;
case 3:
bond = new OrderQueryBond(IBond.Order.TRIPLE, SilentChemObjectBuilder.getInstance());
break;
}
return bond;
}
// TODO handle bond expression
}
return null;
}
use of ambit2.sln.SLNBond 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.SLNBond 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.SLNBond 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.SLNBond 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);
}
Aggregations