Search in sources :

Example 1 with SimpleGraph

use of org._3pq.jgrapht.graph.SimpleGraph in project Smiles2Monomers by yoann-dufresne.

the class Planarity method testCycles.

private boolean testCycles(Biconnected bc) {
    Set<SimpleCycle> cycles = bc.getSeparatedCycles();
    Iterator<SimpleCycle> i = cycles.iterator();
    if (!i.hasNext())
        return true;
    SimpleCycle mainCycle = i.next();
    List<Segment> segments = bc.getSegments(mainCycle);
    switch(segments.size()) {
        case 0:
            return true;
        case 1:
            Segment s = segments.get(0);
            if (s.isStringIn(mainCycle))
                return true;
            else {
                System.err.println("TODO : find separated cycle");
                return false;
            }
        default:
            SimpleGraph comp = new CompatibilityGraph(mainCycle, segments);
            if (!this.tc.isTwoColorable(comp))
                return false;
            else {
                for (Segment s2 : segments) if (!this.isPlanar(s2))
                    return false;
                return true;
            }
    }
}
Also used : SimpleGraph(org._3pq.jgrapht.graph.SimpleGraph) SimpleCycle(org.openscience.cdk.ringsearch.cyclebasis.SimpleCycle) CompatibilityGraph(algorithms.utils.planarity.CompatibilityGraph) Segment(algorithms.utils.planarity.Segment)

Example 2 with SimpleGraph

use of org._3pq.jgrapht.graph.SimpleGraph in project Smiles2Monomers by yoann-dufresne.

the class PlanarityTest method main.

public static void main(String[] args) {
    String pepDBname = "datas/peptides.csv";
    // Loading databases
    PolymersJsonLoader pcl = new PolymersJsonLoader(new MonomersDB());
    PolymersDB pepDB = pcl.loadFile(pepDBname);
    // Tools
    Planarity pt = new Planarity();
    for (Polymer pep : pepDB.getObjects()) {
        System.out.println(pep.getName() + " : ");
        IMolecule mol = null;
        try {
            mol = SmilesConverter.conv.transform(pep.getSmiles());
        } catch (InvalidSmilesException e) {
            System.err.println("Impossible to parse " + pep.getName() + " id:" + pep.getId());
            continue;
        }
        SimpleGraph g = MoleculeGraphs.getMoleculeGraph(mol);
        System.out.println("planar : " + pt.isPlanar(g) + "\n");
    }
}
Also used : IMolecule(org.openscience.cdk.interfaces.IMolecule) PolymersDB(db.PolymersDB) PolymersJsonLoader(io.loaders.json.PolymersJsonLoader) MonomersDB(db.MonomersDB) SimpleGraph(org._3pq.jgrapht.graph.SimpleGraph) Polymer(model.Polymer) Planarity(algorithms.Planarity) InvalidSmilesException(org.openscience.cdk.exception.InvalidSmilesException)

Aggregations

SimpleGraph (org._3pq.jgrapht.graph.SimpleGraph)2 Planarity (algorithms.Planarity)1 CompatibilityGraph (algorithms.utils.planarity.CompatibilityGraph)1 Segment (algorithms.utils.planarity.Segment)1 MonomersDB (db.MonomersDB)1 PolymersDB (db.PolymersDB)1 PolymersJsonLoader (io.loaders.json.PolymersJsonLoader)1 Polymer (model.Polymer)1 InvalidSmilesException (org.openscience.cdk.exception.InvalidSmilesException)1 IMolecule (org.openscience.cdk.interfaces.IMolecule)1 SimpleCycle (org.openscience.cdk.ringsearch.cyclebasis.SimpleCycle)1