Search in sources :

Example 1 with SLNContainer

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;
}
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 2 with SLNContainer

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;
}
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 3 with 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;
}
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 4 with SLNContainer

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

Example 5 with SLNContainer

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;
}
Also used : SLNContainer(ambit2.sln.SLNContainer) IQueryAtomContainer(org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer)

Aggregations

SLNContainer (ambit2.sln.SLNContainer)25 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)7 CompositionRelation (ambit2.base.relation.composition.CompositionRelation)5 IAtom (org.openscience.cdk.interfaces.IAtom)5 IQueryAtomContainer (org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer)5 AmbitIOException (ambit2.base.exceptions.AmbitIOException)4 SLNAtom (ambit2.sln.SLNAtom)4 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 IBond (org.openscience.cdk.interfaces.IBond)4 SLNBond (ambit2.sln.SLNBond)3 HashMap (java.util.HashMap)3 CDKException (org.openscience.cdk.exception.CDKException)3 IStructureRecord (ambit2.base.interfaces.IStructureRecord)2 TopLayer (ambit2.smarts.TopLayer)2 ArrayList (java.util.ArrayList)2 IQueryAtom (org.openscience.cdk.isomorphism.matchers.IQueryAtom)2 QueryAtomContainer (org.openscience.cdk.isomorphism.matchers.QueryAtomContainer)2 StructureRecord (ambit2.base.data.StructureRecord)1 Proportion (ambit2.base.relation.composition.Proportion)1