Search in sources :

Example 1 with InvalidSmilesException

use of org.openscience.cdk.exception.InvalidSmilesException 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 2 with InvalidSmilesException

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

the class TreeWidthTests method test.

@Test
public void test() {
    MolTreeWidth mtw = new MolTreeWidth();
    Polymer pep = null;
    try {
        pep = this.pepDB.getObject("250");
    } catch (NullPointerException e) {
        e.printStackTrace();
    }
    try {
        assertEquals(2, mtw.calculateTreeWidth(SmilesConverter.conv.transform(pep.getSmiles())));
    } catch (InvalidSmilesException e) {
        System.err.println("Impossible to parse smiles");
    }
}
Also used : Polymer(model.Polymer) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException) Test(org.junit.Test)

Example 3 with InvalidSmilesException

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

the class OverlapData method main.

public static void main(String[] args) {
    // Norine Loading
    MonomersJsonLoader monosLoader = new MonomersJsonLoader();
    MonomersDB norMonos = monosLoader.loadFile("data/monomers.json");
    PolymersJsonLoader loader = new PolymersJsonLoader(norMonos);
    PolymersDB norine = loader.loadFile("data/peptides_clean.json");
    // CCD Loading
    MonomersDB ccdMonos = monosLoader.loadFile("data/pdbe_monos_min.json");
    loader = new PolymersJsonLoader(ccdMonos);
    PolymersDB ccd = loader.loadFile("data/pdbe_polys_clean.json");
    // Norine smiles generation
    HashMap<String, Polymer> polymers = new HashMap<>();
    for (Polymer poly : norine.getObjects()) {
        String smiles = null;
        try {
            smiles = SmilesConverter.conv.toCanonicalSmiles(poly.getSmiles());
        } catch (InvalidSmilesException e) {
            e.printStackTrace();
            continue;
        }
        polymers.put(smiles, poly);
    }
    // Test overlapping peptides
    int overlap = 0;
    for (Polymer poly : ccd.getObjects()) {
        String smiles = null;
        try {
            smiles = SmilesConverter.conv.toCanonicalSmiles(poly.getSmiles());
        } catch (InvalidSmilesException e) {
            e.printStackTrace();
            continue;
        }
        if (polymers.containsKey(smiles)) {
            System.out.println(polymers.get(smiles).getName());
            overlap++;
        }
    }
    System.out.println("Total peptides overlapping : " + overlap);
    // Norine smiles generation
    HashMap<String, Monomer> monomers = new HashMap<>();
    for (Monomer mono : norMonos.getObjects()) {
        String smiles = null;
        try {
            smiles = SmilesConverter.conv.toCanonicalSmiles(mono.getSmiles());
        } catch (InvalidSmilesException e) {
            e.printStackTrace();
            continue;
        }
        monomers.put(smiles, mono);
    }
    // Test overlapping peptides
    overlap = 0;
    for (Monomer mono : ccdMonos.getObjects()) {
        String smiles = null;
        try {
            smiles = SmilesConverter.conv.toCanonicalSmiles(mono.getSmiles());
        } catch (InvalidSmilesException e) {
            e.printStackTrace();
            continue;
        }
        if (monomers.containsKey(smiles)) {
            System.out.println(monomers.get(smiles).getName());
            overlap++;
        }
    }
    System.out.println("Total monomers overlapping : " + overlap + "/" + ccdMonos.size());
}
Also used : MonomersJsonLoader(io.loaders.json.MonomersJsonLoader) HashMap(java.util.HashMap) PolymersDB(db.PolymersDB) MonomersDB(db.MonomersDB) PolymersJsonLoader(io.loaders.json.PolymersJsonLoader) Polymer(model.Polymer) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException) Monomer(model.Monomer)

Example 4 with InvalidSmilesException

use of org.openscience.cdk.exception.InvalidSmilesException 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 5 with InvalidSmilesException

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

the class ResidueCreator method getResiduesWithRule.

/*
	 * Search Residues for one monomer and one rule.
	 */
private Set<Residue> getResiduesWithRule(Residue res, Rule rule) {
    Set<Residue> residues = new HashSet<>();
    IMolecule ruleMol = null;
    try {
        ruleMol = SmilesConverter.conv.transform(rule.getFormula(), false, false, true);
    } catch (InvalidSmilesException e) {
        System.err.println("Impossible to parse " + rule.getName() + " rule");
        return residues;
    }
    boolean status = false;
    try {
        status = UniversalIsomorphismTester.isSubgraph(res.getMolecule(), ruleMol);
    } catch (CDKException e) {
        e.printStackTrace();
    }
    // If rule is found
    if (status) {
        List<List<RMap>> matches = null;
        try {
            matches = UniversalIsomorphismTester.getSubgraphAtomsMaps(res.getMolecule(), ruleMol);
        } catch (CDKException e) {
            e.printStackTrace();
        }
        if (!"".equals(rule.getExclusion()))
            for (String exclusion : rule.getExclusion()) this.removeExclusions(matches, exclusion, res.getMolecule());
        for (List<RMap> match : matches) {
            Set<Residue> residuesByMatch = this.createResidue(match, rule, res);
            residues.addAll(residuesByMatch);
        }
    }
    return residues;
}
Also used : IMolecule(org.openscience.cdk.interfaces.IMolecule) Residue(model.Residue) CDKException(org.openscience.cdk.exception.CDKException) ArrayList(java.util.ArrayList) List(java.util.List) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException) RMap(org.openscience.cdk.isomorphism.mcss.RMap) HashSet(java.util.HashSet)

Aggregations

InvalidSmilesException (org.openscience.cdk.exception.InvalidSmilesException)14 IMolecule (org.openscience.cdk.interfaces.IMolecule)8 Polymer (model.Polymer)4 Test (org.junit.Test)4 CDKException (org.openscience.cdk.exception.CDKException)4 MonomersDB (db.MonomersDB)3 PolymersDB (db.PolymersDB)3 PolymersJsonLoader (io.loaders.json.PolymersJsonLoader)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Monomer (model.Monomer)3 BufferedWriter (java.io.BufferedWriter)2 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 Molecule (org.openscience.cdk.Molecule)2 RMap (org.openscience.cdk.isomorphism.mcss.RMap)2 StructureDiagramGenerator (org.openscience.cdk.layout.StructureDiagramGenerator)2