Search in sources :

Example 1 with IMolecule

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

the class SmilesGenerator method createSMILES.

/**
 *  Generate canonical SMILES from the <code>molecule</code>. This method
 *  canonicaly lables the molecule but dose not perform any checks on the
 *  chemical validity of the molecule. This method also takes care of multiple
 *  molecules.
 *  IMPORTANT: A precomputed Set of All Rings (SAR) can be passed to this
 *  SmilesGenerator in order to avoid recomputing it. Use setRings() to
 *  assign the SAR.
 *
 * @param  molecule                 The molecule to evaluate.
 * @param  chiral                   true=SMILES will be chiral, false=SMILES.
 *      will not be chiral.
 * @param  doubleBondConfiguration  Should E/Z configurations be read at these positions? If the flag at position X is set to true,
 *                                  an E/Z configuration will be written from coordinates around bond X, if false, it will be ignored.
 *                                  If flag is true for a bond which does not constitute a valid double bond configuration, it will be
 *                                  ignored (meaning setting all to true will create E/Z indication will be pu in the smiles wherever
 *                                  possible, but note the coordinates might be arbitrary).
 * @exception CDKException          At least one atom has no Point2D;
 *      coordinates are needed for crating the chiral smiles. This excpetion
 *      can only be thrown if chiral smiles is created, ignore it if you want a
 *      non-chiral smiles (createSMILES(AtomContainer) does not throw an
 *      exception).
 * @see                             org.openscience.cdk.graph.invariant.CanonicalLabeler#canonLabel(IAtomContainer)
 * @return the SMILES representation of the molecule
 */
public synchronized String createSMILES(IAtomContainer molecule, boolean chiral, boolean[] doubleBondConfiguration) throws CDKException {
    IMoleculeSet moleculeSet = ConnectivityChecker.partitionIntoMolecules(molecule);
    if (moleculeSet.getMoleculeCount() > 1) {
        StringBuffer fullSMILES = new StringBuffer();
        for (int i = 0; i < moleculeSet.getAtomContainerCount(); i++) {
            IMolecule molPart = moleculeSet.getMolecule(i);
            fullSMILES.append(createSMILESWithoutCheckForMultipleMolecules(molPart, chiral, doubleBondConfiguration));
            if (i < (moleculeSet.getAtomContainerCount() - 1)) {
                // are there more molecules?
                fullSMILES.append('.');
            }
        }
        return fullSMILES.toString();
    } else {
        return (createSMILESWithoutCheckForMultipleMolecules(molecule, chiral, doubleBondConfiguration));
    }
}
Also used : IMoleculeSet(org.openscience.cdk.interfaces.IMoleculeSet) IMolecule(org.openscience.cdk.interfaces.IMolecule)

Example 2 with IMolecule

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

the class IsomorphismTests method initMappingTest.

@Test
public void initMappingTest() {
    List<MappedChain> mbs = Isomorphism.searchFromPreviousMapping(this.mb0, this.ext1, MatchingType.STRONG);
    if (mbs.size() != 2)
        fail("2 matches needed");
    boolean isGood = true;
    for (MappedChain mb : mbs) {
        IMolecule mol = mb.getChemObject().getMolecule();
        IAtom a1 = (mol.getAtom(mb.getAtomsMapping().get(0)));
        IAtom a2 = (mol.getAtom(mb.getAtomsMapping().get(1)));
        if (!((a1.getSymbol().equals("C") && a2.getSymbol().equals("S")) || (a1.getSymbol().equals("S") && a2.getSymbol().equals("C"))))
            isGood = false;
    }
    Assert.assertTrue(isGood);
}
Also used : MappedChain(algorithms.isomorphism.chains.MappedChain) IMolecule(org.openscience.cdk.interfaces.IMolecule) IAtom(org.openscience.cdk.interfaces.IAtom) Test(org.junit.Test)

Example 3 with IMolecule

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

the class LoadersTests method addaTest.

@Test
public void addaTest() {
    String smiles = "CC(C=C(C)C=CC(C(C)C(=O)O)N)C(CC1=CC=CC=C1)OC";
    try {
        smiles = SmilesConverter.conv.toCanonicalSmiles(smiles);
    } catch (InvalidSmilesException e) {
        System.err.println("Impossible to parse " + smiles);
    }
    Monomer adda = new Monomer("Adda", "Adda", smiles);
    IMolecule mol = adda.getMolecule();
    Assert.assertTrue("O=C(O)C(C)C(N)C=CC(=CC(C)C(OC)Cc1ccccc1)C".equals(SmilesConverter.conv.mol2Smiles(mol)));
}
Also used : IMolecule(org.openscience.cdk.interfaces.IMolecule) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException) Monomer(model.Monomer) Test(org.junit.Test)

Example 4 with IMolecule

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

the class PolymersToCanonicalSmiles method modify.

public static void modify(String pepFile) {
    // Loading
    PolymersJsonLoader pjl = new PolymersJsonLoader(new MonomersDB());
    PolymersDB db = pjl.loadFile(pepFile);
    // transform all smiles
    for (Polymer pep : db.getObjects()) {
        IMolecule mol = pep.getMolecule();
        String smiles = SmilesConverter.conv.mol2Smiles(mol);
        pep.setSmiles(smiles);
    }
    // Saving
    pjl.saveFile(db, pepFile);
}
Also used : IMolecule(org.openscience.cdk.interfaces.IMolecule) PolymersDB(db.PolymersDB) PolymersJsonLoader(io.loaders.json.PolymersJsonLoader) MonomersDB(db.MonomersDB) Polymer(model.Polymer)

Example 5 with IMolecule

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

the class PictureCoverageGenerator method createPNG.

public ColorsMap createPNG(Coverage coverage, File outfile) {
    ColorsMap coverageColors = new ColorsMap();
    AtomColorer ac = this.cag.getColorer();
    IMolecule mol = coverage.getMolecule(false);
    List<Color> colors = ColorsGenerator.HsbColorsGeneration(coverage.nbMatchesForCoverage());
    int i = 0;
    for (Match match : coverage.getUsedMatches()) {
        Residue res = match.getResidue();
        List<Color> matchesColor = coverageColors.containsKey(res) ? coverageColors.get(res) : new ArrayList<Color>();
        for (int idx : match.getAtoms()) {
            if (!"H".equals(coverage.getMolecule(true).getAtom(idx).getSymbol()))
                ac.setColor(mol.getAtom(idx), colors.get(i));
        }
        matchesColor.add(colors.get(i));
        coverageColors.put(res, matchesColor);
        i++;
    }
    this.createPNG(mol, outfile);
    ac.resetColors();
    return coverageColors;
}
Also used : IMolecule(org.openscience.cdk.interfaces.IMolecule) Residue(model.Residue) Color(java.awt.Color) AtomColorer(io.imgs.coloration.ColoredAtomGenerator.AtomColorer) Match(algorithms.utils.Match)

Aggregations

IMolecule (org.openscience.cdk.interfaces.IMolecule)28 IAtom (org.openscience.cdk.interfaces.IAtom)12 ArrayList (java.util.ArrayList)7 InvalidSmilesException (org.openscience.cdk.exception.InvalidSmilesException)7 Residue (model.Residue)6 IBond (org.openscience.cdk.interfaces.IBond)6 HashSet (java.util.HashSet)5 Test (org.junit.Test)5 CDKException (org.openscience.cdk.exception.CDKException)5 MappedChain (algorithms.isomorphism.chains.MappedChain)4 Match (algorithms.utils.Match)4 HashMap (java.util.HashMap)4 Rule (model.Rule)3 JSONObject (org.json.simple.JSONObject)3 Chain (algorithms.isomorphism.chains.Chain)2 BondMapping (algorithms.isomorphism.chains.Extension.BondMapping)2 MonomersDB (db.MonomersDB)2 PolymersDB (db.PolymersDB)2 PolymersJsonLoader (io.loaders.json.PolymersJsonLoader)2 IOException (java.io.IOException)2