Search in sources :

Example 11 with IAtomContainerSet

use of org.openscience.cdk.interfaces.IAtomContainerSet in project ambit-mirror by ideaconsult.

the class ReactionSequence method generateSequenceStepForReactionInstance.

public void generateSequenceStepForReactionInstance(ReactionSequenceLevel level, int moleculeIndex, GenericReactionInstance gri) throws Exception {
    ReactionSequenceStep step = new ReactionSequenceStep();
    step.reaction = gri.reaction;
    // IAtomContainer mol = level.molecules.get(moleculeIndex);
    step.reactionScore = gri.reactionScore;
    IAtomContainerSet productFrags = ConnectivityChecker.partitionIntoMolecules(gri.products);
    step.outputMolecules = new ArrayList<IAtomContainer>();
    for (IAtomContainer frag : productFrags.atomContainers()) {
        step.outputMolecules.add(frag);
        String inchiKey = setMoleculeInchiKey(frag);
        registerMolInchiKey(frag, inchiKey, level.levelIndex + 1);
        // Set new molecule status
        if (usedInchies.get(inchiKey).molecules.size() > 1)
            setMoleculeStatus(frag, MoleculeStatus.EQUIVALENT_TO_OTHER_MOLECULE);
        else {
            if (startMatDB.isStartingMaterial(inchiKey))
                setMoleculeStatus(frag, MoleculeStatus.STARTING_MATERIAL);
            else
                setMoleculeStatus(frag, MoleculeStatus.ADDED_TO_LEVEL);
        }
    }
    level.associateStep(moleculeIndex, step);
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet)

Example 12 with IAtomContainerSet

use of org.openscience.cdk.interfaces.IAtomContainerSet in project ambit-mirror by ideaconsult.

the class ReactionSequence method getMaxProductFragment.

IAtomContainer getMaxProductFragment(IAtomContainer products) {
    int maxSize = -1;
    IAtomContainer maxFrag = null;
    IAtomContainerSet productFrags = ConnectivityChecker.partitionIntoMolecules(products);
    for (IAtomContainer frag : productFrags.atomContainers()) if (maxSize < frag.getAtomCount()) {
        maxFrag = frag;
        maxSize = frag.getAtomCount();
    }
    return maxFrag;
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet)

Example 13 with IAtomContainerSet

use of org.openscience.cdk.interfaces.IAtomContainerSet in project ambit-mirror by ideaconsult.

the class StructureEditorProcessor method process.

@Override
public String process(IStructureRecord record) throws AmbitException {
    try {
        MOL_TYPE mtype = MOL_TYPE.valueOf(record.getFormat());
        IAtomContainer mol = null;
        switch(mtype) {
            case SDF:
                {
                    MoleculeReader reader = new MoleculeReader();
                    mol = reader.process(record);
                    AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol);
                    reader = null;
                    break;
                }
            case CSV:
                {
                    // smiles
                    SmilesParserWrapper p = SmilesParserWrapper.getInstance(SMILES_PARSER.CDK);
                    mol = p.parseSmiles(record.getContent());
                    break;
                }
            default:
                throw new AmbitException("Unsupported format");
        }
        // actions
        if (mol != null && mol.getAtomCount() > 0)
            switch(command) {
                case layout:
                    {
                        IAtomContainerSet molecules = new AtomContainerSet();
                        CompoundImageTools cit = new CompoundImageTools();
                        cit.generate2D(mol, true, molecules);
                        mol = MoleculeTools.newAtomContainer(mol.getBuilder());
                        for (IAtomContainer m : molecules.atomContainers()) {
                            mol.add(m);
                        }
                        break;
                    }
                case aromatize:
                    if (mol != null)
                        CDKHueckelAromaticityDetector.detectAromaticity(mol);
                    break;
                case dearomatize:
                    if (mol != null) {
                        Kekulization.kekulize(mol);
                        for (IBond bond : mol.bonds()) bond.setFlag(CDKConstants.ISAROMATIC, false);
                    }
                    break;
                default:
                    throw new AmbitException("Unknown command");
            }
        StringWriter w = new StringWriter();
        SDFWriter writer = new SDFWriter(w);
        writer.write(mol);
        writer.close();
        return w.toString();
    } catch (AmbitException x) {
        throw x;
    } catch (Exception x) {
        throw new AmbitException(x);
    }
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) MoleculeReader(ambit2.core.processors.structure.MoleculeReader) StringWriter(java.io.StringWriter) MOL_TYPE(ambit2.base.interfaces.IStructureRecord.MOL_TYPE) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) IBond(org.openscience.cdk.interfaces.IBond) SDFWriter(org.openscience.cdk.io.SDFWriter) SmilesParserWrapper(ambit2.core.smiles.SmilesParserWrapper) AtomContainerSet(org.openscience.cdk.silent.AtomContainerSet) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) AmbitException(net.idea.modbcum.i.exceptions.AmbitException) AmbitException(net.idea.modbcum.i.exceptions.AmbitException)

Example 14 with IAtomContainerSet

use of org.openscience.cdk.interfaces.IAtomContainerSet in project ambit-mirror by ideaconsult.

the class SmartsManager method fragmentSearchIn.

boolean fragmentSearchIn(IAtomContainer target) throws Exception {
    boolean noComponentsSpecified = true;
    for (int i = 0; i < parser.fragmentComponents.size(); i++) {
        if (parser.fragmentComponents.get(i).intValue() > 0) {
            noComponentsSpecified = false;
            break;
        }
    }
    if (parser.hasRecursiveSmarts) {
        clearQueryRecMatches();
        getQueryRecMatches(target);
    }
    if (// There are no zero level brackets i.e. each
    noComponentsSpecified) // fragments maps anywhere
    {
        for (int i = 0; i < parser.fragments.size(); i++) {
            query = parser.fragments.get(i);
            if (!mappingIn(target))
                return (false);
        }
        return (true);
    }
    // Handle Component Level Grouping (zero level brackets are used)
    IAtomContainerSet ms = ConnectivityChecker.partitionIntoMolecules(target);
    // This is a simple preliminary check
    if (ms.getAtomContainerCount() < parser.maxCompNumber)
        return (false);
    // Each query fragment which is in a component with number > 0 is
    // searched individually against
    // each target component.
    // The query fragments which are not in a zero level brackets (comp.
    // number = 0) are searched
    // against the "whole target" i.e. to found it at least in on the of the
    // target components
    compFrags.clear();
    boolean res;
    for (int i = 0; i < parser.fragments.size(); i++) {
        if (parser.fragmentComponents.get(i).intValue() == 0) {
            query = parser.fragments.get(i);
            res = mappingIn(target);
            if (!res)
                // This non-component fragment is not found
                return (false);
        // in the target
        } else
            // parser.fragmentComponents.get(i));
            compFrags.add(new Integer(i));
    }
    fragMaps = new boolean[compFrags.size()][ms.getAtomContainerCount()];
    components = new int[compFrags.size()];
    for (int i = 0; i < compFrags.size(); i++) {
        components[i] = parser.fragmentComponents.get(compFrags.get(i).intValue()).intValue();
        for (int j = 0; j < ms.getAtomContainerCount(); j++) {
            query = parser.fragments.get(compFrags.get(i).intValue());
            fragMaps[i][j] = mappingIn(ms.getAtomContainer(j));
        }
    }
    // printComponentFrags();
    return (checkComponentMapings());
}
Also used : IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet)

Example 15 with IAtomContainerSet

use of org.openscience.cdk.interfaces.IAtomContainerSet in project ambit-mirror by ideaconsult.

the class SmartsManager method getAllIsomorphismMappings.

public IAtomContainerSet getAllIsomorphismMappings(IAtomContainer target) throws Exception {
    IAtomContainerSet s = MoleculeTools.newAtomContainerSet(SilentChemObjectBuilder.getInstance());
    if (query == null)
        return (s);
    if (FlagUseCDKIsomorphismTester) {
        if (query.getAtomCount() < 3) {
            if (FlagSetSmartsDataForTarget)
                parser.setSMARTSData(target);
            if (parser.hasRecursiveSmarts) {
                clearQueryRecMatches();
                getQueryRecMatches(target);
            }
        }
        if (query.getAtomCount() == 1) {
            List<IAtom> v = getAtomMappingsFor1AtomQuery(target, query);
            for (int i = 0; i < v.size(); i++) {
                IAtomContainer c = MoleculeTools.newMolecule(SilentChemObjectBuilder.getInstance());
                c.addAtom(v.get(i));
                s.addAtomContainer(c);
            }
            return (s);
        }
        if (query.getAtomCount() == 2) {
            return (getAllIsomorphismMappingsFor2AtomQuery(target, query));
        }
        // The case query.getAtomCount() >= 3
        List<List<RMap>> maps = getBondMappings(target);
        for (List<RMap> bondMap : maps) {
            IAtomContainer c = generateFullIsomorphismMapping(bondMap, target, query);
            s.addAtomContainer(c);
        }
        return (s);
    } else // Current Isomorphism Tester is used
    {
    // TODO
    }
    return (s);
}
Also used : IAtomContainer(org.openscience.cdk.interfaces.IAtomContainer) IAtomContainerSet(org.openscience.cdk.interfaces.IAtomContainerSet) ArrayList(java.util.ArrayList) List(java.util.List) RMap(org.openscience.cdk.isomorphism.mcss.RMap) IAtom(org.openscience.cdk.interfaces.IAtom)

Aggregations

IAtomContainerSet (org.openscience.cdk.interfaces.IAtomContainerSet)596 IAtomContainer (org.openscience.cdk.interfaces.IAtomContainer)535 Test (org.junit.Test)327 IAtom (org.openscience.cdk.interfaces.IAtom)284 ArrayList (java.util.ArrayList)223 IReactionSet (org.openscience.cdk.interfaces.IReactionSet)217 IParameterReact (org.openscience.cdk.reaction.type.parameters.IParameterReact)192 IReactionProcess (org.openscience.cdk.reaction.IReactionProcess)166 SetReactionCenter (org.openscience.cdk.reaction.type.parameters.SetReactionCenter)160 ReactionProcessTest (org.openscience.cdk.reaction.ReactionProcessTest)158 CDKException (org.openscience.cdk.exception.CDKException)129 IBond (org.openscience.cdk.interfaces.IBond)57 IReaction (org.openscience.cdk.interfaces.IReaction)56 IChemModel (org.openscience.cdk.interfaces.IChemModel)52 IQueryAtomContainer (org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer)45 InputStream (java.io.InputStream)41 UniversalIsomorphismTester (org.openscience.cdk.isomorphism.UniversalIsomorphismTester)35 QueryAtomContainer (org.openscience.cdk.isomorphism.matchers.QueryAtomContainer)35 IChemSequence (org.openscience.cdk.interfaces.IChemSequence)34 ChemFile (org.openscience.cdk.ChemFile)31