Search in sources :

Example 1 with Molecule

use of org.openscience.cdk.Molecule in project Smiles2Monomers by yoann-dufresne.

the class AbstractChemicalObject method getMol.

private Molecule getMol() {
    if (this.mol == null) {
        try {
            boolean generateCoordinates = this.generateCoordinate == null ? false : this.generateCoordinate;
            boolean explicite = this.explicitHydrogens == null ? false : this.explicitHydrogens;
            if (this.generateH != null && this.generateH.equals(new Boolean(true)))
                this.mol = SmilesConverter.conv.transform(this.smiles, false, generateCoordinates, explicite);
            else
                this.mol = SmilesConverter.conv.transform(this.smiles, true, generateCoordinates, explicite);
        } catch (InvalidSmilesException e) {
            System.err.println("Impossible to parse \"" + this.smiles + "\"");
            Molecule mol = new Molecule();
            return mol;
        }
    }
    return this.mol;
}
Also used : Molecule(org.openscience.cdk.Molecule) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException)

Example 2 with Molecule

use of org.openscience.cdk.Molecule in project Smiles2Monomers by yoann-dufresne.

the class MonomericSpliting method computeCoverage.

/**
 * Calculate an object Coverage with all matches from families.
 * @param pep Peptide to match
 */
public void computeCoverage(Polymer pep) {
    this.coverage = new Coverage(pep);
    this.matcher.setChemicalObject(pep);
    Isomorphism.setMappingStorage(true);
    // Step 1 : Strict Matching
    if (verbose) {
        System.out.println("+Strict matching");
        System.out.println("++Search residues");
    }
    this.matchAllFamilies(MatchingType.STRONG);
    double ratio = this.coverage.getCoverageRatio();
    if (ratio < 1.0) {
        if (verbose)
            System.out.println("++Modulation");
        this.coverage = this.modulation.modulate(this.coverage);
    }
    Coverage save = this.coverage.clone();
    // conditions to go to light matching
    if (!this.allowLightMatchs || ratio == 1.0) {
        Isomorphism.setMappingStorage(false);
        return;
    }
    // TODO : Why if/else ?
    if (this.condition == null)
        this.condition = new ExtendsNTimes(this.retry);
    else
        this.condition.init();
    this.remover.init();
    // Successive matchings
    int depth = 0;
    while (this.coverage.getCoverageRatio() < 1.0 && this.condition.toContinue(this.coverage)) {
        depth++;
        // Contract the atomic graph to monomeric graph
        ContractedGraph contracted = new ContractedGraph(this.coverage);
        // Remove monomers from the current solution to try with other matching strategy
        this.remover.remove(this.coverage, contracted);
        // Create a masked molecule to only search on free polymer areas
        Molecule mol = DeepenMatcher.mask(this.coverage);
        this.coverage.setCurrentMaskedMol(mol);
        OtherChemicalObject tmp = new OtherChemicalObject(mol);
        this.matcher.setChemicalObject(tmp);
        if (verbose) {
            System.out.println("+Light matching, depth " + depth);
            System.out.println("++Search residues");
        }
        // Compute for all families with ligth matching
        this.matchAllFamilies(MatchingType.LIGHT);
        // Re-compute coverage
        this.coverage.calculateGreedyCoverage();
        if (this.coverage.getCoverageRatio() < 1.0) {
            if (verbose)
                System.out.println("++Modulation");
            this.coverage = this.modulation.modulate(this.coverage);
        }
        if (this.coverage.getCoverageRatio() > save.getCoverageRatio())
            save = this.coverage.clone();
        this.remover.nextLevel();
    }
    Isomorphism.setMappingStorage(false);
    if (save.getCoverageRatio() > this.coverage.getCoverageRatio())
        this.coverage = save;
}
Also used : Molecule(org.openscience.cdk.Molecule) ExtendsNTimes(algorithms.isomorphism.conditions.ExtendsNTimes) ContractedGraph(model.graph.ContractedGraph) Coverage(algorithms.utils.Coverage) OtherChemicalObject(model.OtherChemicalObject)

Example 3 with Molecule

use of org.openscience.cdk.Molecule in project Smiles2Monomers by yoann-dufresne.

the class PictureGenerator method transform.

/**/
public Molecule transform(String smiles) throws InvalidSmilesException {
    Molecule imol = null;
    imol = new Molecule(this.sp.parseSmiles(smiles));
    for (IAtom a : imol.atoms()) a.setImplicitHydrogenCount(0);
    StructureDiagramGenerator sdg = new StructureDiagramGenerator(imol);
    try {
        sdg.generateCoordinates();
    } catch (CDKException e) {
        System.err.println(smiles);
        e.printStackTrace();
    }
    imol = new Molecule(sdg.getMolecule());
    return imol;
}
Also used : Molecule(org.openscience.cdk.Molecule) IMolecule(org.openscience.cdk.interfaces.IMolecule) CDKException(org.openscience.cdk.exception.CDKException) IAtom(org.openscience.cdk.interfaces.IAtom) StructureDiagramGenerator(org.openscience.cdk.layout.StructureDiagramGenerator)

Example 4 with Molecule

use of org.openscience.cdk.Molecule in project Smiles2Monomers by yoann-dufresne.

the class SmilesConverter method transform.

public Molecule transform(String smiles, boolean addHydrogens, boolean calculateCoordinate, boolean expliciteHydrogens) throws InvalidSmilesException {
    Molecule imol = null;
    try {
        imol = new Molecule(sp.parseSmiles(smiles));
        // Add hydrogens
        if (addHydrogens) {
            CDKHydrogenAdder adder = CDKHydrogenAdder.getInstance(imol.getBuilder());
            try {
                adder.addImplicitHydrogens(imol);
                if (expliciteHydrogens)
                    AtomContainerManipulator.convertImplicitToExplicitHydrogens(imol);
            } catch (CDKException e) {
                e.printStackTrace();
            }
        } else {
            for (IAtom a : imol.atoms()) a.setImplicitHydrogenCount(0);
            if (!expliciteHydrogens)
                imol = new Molecule(AtomContainerManipulator.removeHydrogens(imol));
        }
        if (calculateCoordinate) {
            StructureDiagramGenerator sdg = new StructureDiagramGenerator(imol);
            try {
                sdg.generateCoordinates();
            } catch (CDKException e) {
                System.err.println(smiles);
                e.printStackTrace();
            }
            imol = new Molecule(sdg.getMolecule());
        }
    } catch (InvalidSmilesException e) {
        throw e;
    }
    return imol;
}
Also used : Molecule(org.openscience.cdk.Molecule) IMolecule(org.openscience.cdk.interfaces.IMolecule) CDKException(org.openscience.cdk.exception.CDKException) CDKHydrogenAdder(org.openscience.cdk.tools.CDKHydrogenAdder) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException) IAtom(org.openscience.cdk.interfaces.IAtom) StructureDiagramGenerator(org.openscience.cdk.layout.StructureDiagramGenerator)

Example 5 with Molecule

use of org.openscience.cdk.Molecule in project Smiles2Monomers by yoann-dufresne.

the class DeepenMatcher method mask.

/**
 * Create a new molecule without covered atoms
 */
public static Molecule mask(Coverage coverage) {
    Molecule covMol = coverage.getChemicalObject().getMolecule();
    Molecule mol = new Molecule();
    List<Integer> coveredIdxs = DeepenMatcher.calculateCoveredAtoms(coverage);
    for (IAtom atom : covMol.atoms()) if (!coveredIdxs.contains(covMol.getAtomNumber(atom)))
        mol.addAtom(atom);
    HashSet<IBond> bonds = new HashSet<>();
    for (IAtom atom : mol.atoms()) {
        for (IBond bond : covMol.getConnectedBondsList(atom)) if (mol.contains(bond.getAtom(0)) && mol.contains(bond.getAtom(1))) {
            if (!bonds.contains(bond)) {
                mol.addBond(bond);
                bonds.add(bond);
            }
        }
    }
    return mol;
}
Also used : Molecule(org.openscience.cdk.Molecule) IMolecule(org.openscience.cdk.interfaces.IMolecule) IBond(org.openscience.cdk.interfaces.IBond) IAtom(org.openscience.cdk.interfaces.IAtom) HashSet(java.util.HashSet)

Aggregations

Molecule (org.openscience.cdk.Molecule)8 IAtom (org.openscience.cdk.interfaces.IAtom)6 IMolecule (org.openscience.cdk.interfaces.IMolecule)6 IBond (org.openscience.cdk.interfaces.IBond)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Residue (model.Residue)2 CDKException (org.openscience.cdk.exception.CDKException)2 InvalidSmilesException (org.openscience.cdk.exception.InvalidSmilesException)2 StructureDiagramGenerator (org.openscience.cdk.layout.StructureDiagramGenerator)2 ExtendsNTimes (algorithms.isomorphism.conditions.ExtendsNTimes)1 Coverage (algorithms.utils.Coverage)1 FamilyDB (db.FamilyDB)1 ArrayList (java.util.ArrayList)1 Family (model.Family)1 OtherChemicalObject (model.OtherChemicalObject)1 Rule (model.Rule)1 Replacement (model.Rule.Replacement)1 ContractedGraph (model.graph.ContractedGraph)1 Bond (org.openscience.cdk.Bond)1