Search in sources :

Example 1 with SLNBond

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;
}
Also used : AnyOrderQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond) SingleOrAromaticBond(ambit2.smarts.SingleOrAromaticBond) SingleBondAromaticityNotSpecified(ambit2.smarts.SingleBondAromaticityNotSpecified) DoubleNonAromaticBond(ambit2.smarts.DoubleNonAromaticBond) DoubleBondAromaticityNotSpecified(ambit2.smarts.DoubleBondAromaticityNotSpecified) AnyOrderQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond) OrderQueryBond(org.openscience.cdk.isomorphism.matchers.smarts.OrderQueryBond) IQueryBond(org.openscience.cdk.isomorphism.matchers.IQueryBond) SingleNonAromaticBond(ambit2.smarts.SingleNonAromaticBond)

Example 2 with SLNBond

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;
}
Also used : HashMap(java.util.HashMap) IQueryAtom(org.openscience.cdk.isomorphism.matchers.IQueryAtom) SLNBond(ambit2.sln.SLNBond) SLNAtom(ambit2.sln.SLNAtom) IQueryBond(org.openscience.cdk.isomorphism.matchers.IQueryBond) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) QueryAtomContainer(org.openscience.cdk.isomorphism.matchers.QueryAtomContainer) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 3 with SLNBond

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;
}
Also used : HashMap(java.util.HashMap) IBond(org.openscience.cdk.interfaces.IBond) SLNBond(ambit2.sln.SLNBond) SLNAtom(ambit2.sln.SLNAtom) SLNContainer(ambit2.sln.SLNContainer) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 4 with SLNBond

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;
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) QueryAtomContainer(org.openscience.cdk.isomorphism.matchers.QueryAtomContainer) AtomContainer(org.openscience.cdk.AtomContainer) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer) HashMap(java.util.HashMap) SLNBond(ambit2.sln.SLNBond) IBond(org.openscience.cdk.interfaces.IBond) SLNAtom(ambit2.sln.SLNAtom) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 5 with SLNBond

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);
}
Also used : SLNBond(ambit2.sln.SLNBond) IAtom(org.openscience.cdk.interfaces.IAtom)

Aggregations

SLNBond (ambit2.sln.SLNBond)7 IAtom (org.openscience.cdk.interfaces.IAtom)5 SLNAtom (ambit2.sln.SLNAtom)4 HashMap (java.util.HashMap)3 IBond (org.openscience.cdk.interfaces.IBond)3 IQueryBond (org.openscience.cdk.isomorphism.matchers.IQueryBond)3 DoubleNonAromaticBond (ambit2.smarts.DoubleNonAromaticBond)2 SingleNonAromaticBond (ambit2.smarts.SingleNonAromaticBond)2 SingleOrAromaticBond (ambit2.smarts.SingleOrAromaticBond)2 IQueryAtomContainer (org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer)2 QueryAtomContainer (org.openscience.cdk.isomorphism.matchers.QueryAtomContainer)2 AnyOrderQueryBond (org.openscience.cdk.isomorphism.matchers.smarts.AnyOrderQueryBond)2 OrderQueryBond (org.openscience.cdk.isomorphism.matchers.smarts.OrderQueryBond)2 SLNContainer (ambit2.sln.SLNContainer)1 DoubleBondAromaticityNotSpecified (ambit2.smarts.DoubleBondAromaticityNotSpecified)1 SingleBondAromaticityNotSpecified (ambit2.smarts.SingleBondAromaticityNotSpecified)1 ArrayList (java.util.ArrayList)1 AtomContainer (org.openscience.cdk.AtomContainer)1 Bond (org.openscience.cdk.Bond)1 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)1