Search in sources :

Example 1 with Atom

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

the class BonbMatchingTests method setUp.

@Before
public void setUp() throws Exception {
    // cNH
    IAtom a2 = new Atom("C");
    a2.setImplicitHydrogenCount(0);
    a2.setFlag(CDKConstants.ISAROMATIC, true);
    IAtom a1 = new Atom("N");
    a1.setImplicitHydrogenCount(1);
    this.bond1 = new Bond(a1, a2, Order.DOUBLE);
}
Also used : Bond(org.openscience.cdk.Bond) IAtom(org.openscience.cdk.interfaces.IAtom) Atom(org.openscience.cdk.Atom) IAtom(org.openscience.cdk.interfaces.IAtom) Before(org.junit.Before)

Example 2 with Atom

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

the class Biconnected method createBiconnectedComponents.

/*
	 * Function to create biconned components
	 */
@SuppressWarnings("unchecked")
public static List<Biconnected> createBiconnectedComponents(UndirectedGraph g) {
    BiconnectivityInspector bi = new BiconnectivityInspector(g);
    List<Set<UndirectedEdge>> biconnecteds = bi.biconnectedSets();
    List<Biconnected> bcs = new ArrayList<>();
    for (Set<UndirectedEdge> edges : biconnecteds) {
        HashSet<Atom> vertices = new HashSet<>();
        Iterator<UndirectedEdge> i = edges.iterator();
        while (i.hasNext()) {
            UndirectedEdge e = i.next();
            vertices.add((Atom) e.getSource());
            vertices.add((Atom) e.getTarget());
        }
        Biconnected sg = new Biconnected(g, vertices, edges);
        bcs.add(sg);
    }
    return bcs;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) UndirectedEdge(org._3pq.jgrapht.edge.UndirectedEdge) ArrayList(java.util.ArrayList) BiconnectivityInspector(org.openscience.cdk.graph.BiconnectivityInspector) Atom(org.openscience.cdk.Atom) HashSet(java.util.HashSet)

Example 3 with Atom

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

the class Segment method isStringIn.

@SuppressWarnings("unchecked")
public boolean isStringIn(AbstractGraph sg) {
    Iterator<Atom> segIt = this.vertexSet().iterator();
    int cpt = 0;
    while (segIt.hasNext()) {
        Atom a = segIt.next();
        if (sg.vertexSet().contains(a))
            cpt++;
    }
    if (cpt == 2)
        return true;
    return false;
}
Also used : Atom(org.openscience.cdk.Atom)

Example 4 with Atom

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

the class Extension method createBond.

private void createBond(String name0, int h0, boolean arom0, String name1, int h1, boolean arom1, Order ord) {
    if (arom0)
        name0 = name0.toLowerCase();
    if (arom1)
        name1 = name1.toLowerCase();
    List<String> names = new ArrayList<>();
    names.add(name0 + ":" + h0);
    names.add(name1 + ":" + h1);
    Collections.sort(names);
    // this.inverted = !names.get(0).equals(name0 + ":" + h0);
    IAtom c0 = null;
    String n0 = names.get(0);
    if (Extension.savedAtoms.containsKey(n0))
        c0 = Extension.savedAtoms.get(n0);
    else {
        String[] split = n0.split(":");
        char first = Character.toUpperCase(split[0].charAt(0));
        String name = first + split[0].substring(1);
        c0 = new Atom(name);
        c0.setFlag(CDKConstants.ISAROMATIC, Character.isLowerCase(split[0].charAt(0)));
        c0.setImplicitHydrogenCount(new Integer(split[1]));
        Extension.savedAtoms.put(n0, c0);
    }
    IAtom c1 = null;
    String n1 = names.get(1);
    if (Extension.savedAtoms.containsKey(n1))
        c1 = Extension.savedAtoms.get(n1);
    else {
        String[] split = n1.split(":");
        char first = Character.toUpperCase(split[0].charAt(0));
        String name = first + split[0].substring(1);
        c1 = new Atom(name);
        c1.setFlag(CDKConstants.ISAROMATIC, Character.isLowerCase(split[0].charAt(0)));
        c1.setImplicitHydrogenCount(new Integer(split[1]));
        Extension.savedAtoms.put(n1, c1);
    }
    String key = names.get(0) + ord + names.get(1);
    if (Extension.savedBonds.containsKey(key)) {
        this.bond = Extension.savedBonds.get(key);
    } else {
        this.bond = new Bond(c0, c1, ord);
        Extension.savedBonds.put(key, this.bond);
    }
}
Also used : ArrayList(java.util.ArrayList) Bond(org.openscience.cdk.Bond) IBond(org.openscience.cdk.interfaces.IBond) IAtom(org.openscience.cdk.interfaces.IAtom) Atom(org.openscience.cdk.Atom) IAtom(org.openscience.cdk.interfaces.IAtom)

Example 5 with Atom

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

the class Biconnected method getSegments.

/*
	 * Find segments in a biconnected graph
	 */
@SuppressWarnings("unchecked")
public List<Segment> getSegments(SimpleCycle mainCycle) {
    List<Segment> segments = new ArrayList<>();
    Set<UndirectedEdge> absents = new HashSet<>();
    // Add all graph vertices
    Iterator<UndirectedEdge> iv = this.edgeSet().iterator();
    while (iv.hasNext()) absents.add(iv.next());
    // Remove main cycle vertices.
    Iterator<UndirectedEdge> ic = mainCycle.edgeSet().iterator();
    while (ic.hasNext()) absents.remove(ic.next());
    while (absents.size() != 0) {
        // Depth first search for segments
        Set<Atom> segV = new HashSet<>();
        Set<UndirectedEdge> segE = new HashSet<>();
        Stack<UndirectedEdge> stack = new Stack<>();
        UndirectedEdge first = absents.iterator().next();
        stack.push(first);
        segE.add(first);
        while (!stack.isEmpty()) {
            Set<UndirectedEdge> edges = new HashSet<>();
            UndirectedEdge e = stack.pop();
            // Add neighbors edges non already folloed
            edges.addAll(this.edgesOf(e.getSource()));
            edges.addAll(this.edgesOf(e.getTarget()));
            for (UndirectedEdge neighbor : edges) if (absents.contains(neighbor)) {
                stack.push(neighbor);
                absents.remove(neighbor);
            }
            // Add verticies
            segV.add((Atom) e.getSource());
            segV.add((Atom) e.getTarget());
        }
        // Segment creation
        Segment seg = new Segment(segV, segE);
        segments.add(seg);
    }
    return segments;
}
Also used : UndirectedEdge(org._3pq.jgrapht.edge.UndirectedEdge) ArrayList(java.util.ArrayList) Atom(org.openscience.cdk.Atom) HashSet(java.util.HashSet) Stack(java.util.Stack)

Aggregations

Atom (org.openscience.cdk.Atom)6 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3 UndirectedEdge (org._3pq.jgrapht.edge.UndirectedEdge)3 Stack (java.util.Stack)2 Bond (org.openscience.cdk.Bond)2 IAtom (org.openscience.cdk.interfaces.IAtom)2 Set (java.util.Set)1 Before (org.junit.Before)1 BiconnectivityInspector (org.openscience.cdk.graph.BiconnectivityInspector)1 IBond (org.openscience.cdk.interfaces.IBond)1