use of org.openscience.cdk.interfaces.IAtom 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);
}
use of org.openscience.cdk.interfaces.IAtom in project Smiles2Monomers by yoann-dufresne.
the class ResidueJsonLoader method objectFromJson.
@Override
protected Family objectFromJson(JSONObject obj) {
Residue res = new Residue((String) obj.get("mono"), (String) obj.get("smarts"), true);
res.setIdx(((Number) obj.get("id")).intValue());
JSONArray array = (JSONArray) obj.get("links");
for (Object o : array) {
JSONObject jso = (JSONObject) o;
String name = (String) jso.get("name");
Rule rule = null;
try {
rule = this.rules.getObject(name);
} catch (NullPointerException e) {
System.err.println("Unknown link " + name);
}
int idx = ((Number) jso.get("atom")).intValue();
IAtom ia = res.getMolecule().getAtom(idx);
res.addLink(ia, rule);
}
// Family construction
Family fam = new Family();
try {
for (String name : ((String) obj.get("family")).split("€")) {
Monomer m = this.monos.getObject(name);
fam.addMonomer(m);
}
} catch (NullPointerException e) {
System.err.println("Unloaded residue " + res.getMonoName());
}
fam.addResidue(res);
for (Object jso : (JSONArray) obj.get("depandances")) {
int idx = ((Number) jso).intValue();
fam.addDependance(idx, new Integer(res.getId()));
}
return fam;
}
use of org.openscience.cdk.interfaces.IAtom in project Smiles2Monomers by yoann-dufresne.
the class MonomersSerialization method deserializeObject.
private void deserializeObject(Monomer mono, ObjectInputStream ois) {
try {
int nbAtoms = ois.readInt();
if (nbAtoms != mono.getMolecule().getAtomCount()) {
System.err.println("Bad serialized value for atom count in " + mono.getCode());
}
for (IAtom a : mono.getMolecule().atoms()) {
Point2d p = new Point2d(ois.readDouble(), ois.readDouble());
a.setPoint2d(p);
}
} catch (IOException e) {
e.printStackTrace();
}
}
use of org.openscience.cdk.interfaces.IAtom in project Smiles2Monomers by yoann-dufresne.
the class MySMILES method createDFS.
private void createDFS(DFS dfs, AtomNode current, AtomNode from) {
current.state = State.CHECK;
dfs.path.add(current);
List<AtomNode> toExplore = new ArrayList<MySMILES.AtomNode>();
// For all neighbors save enighbors to explore
for (IAtom a : dfs.mol.getConnectedAtomsList(current.atom)) {
AtomNode nei = dfs.nodes.get(a);
if (from != null && nei.atom == from.atom)
continue;
switch(nei.state) {
case FREE:
toExplore.add(nei);
nei.state = State.TOEXPLORE;
case TOEXPLORE:
// TODO better smiles with less () and cycles first
break;
default:
if (nei.rings == null)
nei.rings = new ArrayList<Integer>();
nei.rings.add(dfs.ringNumber);
if (current.rings == null)
current.rings = new ArrayList<Integer>();
current.rings.add(dfs.ringNumber++);
break;
}
}
if (toExplore.size() == 0)
return;
// Sort neighbors to explore.
List<List<AtomNode>> sortedNeighbors = dfs.sort(toExplore, current, dfs.mol);
for (List<AtomNode> similar : sortedNeighbors) {
HashMap<List<AtomNode>, DFS> clones = new HashMap<>();
// Clone if there are most than one possibility
List<List<AtomNode>> alternatives = this.getAllAlternatives(similar);
for (List<AtomNode> alt : alternatives) clones.put(alt, dfs.clone());
// Explore all alternatives for equivalent nodes
DFS bestClone = null;
for (List<AtomNode> alternative : alternatives) {
DFS clone = clones.get(alternative);
for (AtomNode node : alternative) {
node = clone.nodes.get(node.atom);
// To avoid 2 usages of same node if there are rings
if (node.state != State.TOEXPLORE) {
clones.remove(node);
continue;
}
clone.path.add(new TextNode("("));
this.createDFS(clone, node, current);
clone.path.add(new TextNode(")"));
}
// Select best clone
if (bestClone == null)
bestClone = clone;
else if (bestClone.toString().compareTo(clone.toString()) > 0)
bestClone = clone;
}
// Transformation of the current DFS with the best clone extensions.
for (int idx = dfs.path.size(); idx < bestClone.path.size(); idx++) {
Node node = bestClone.path.get(idx);
if (node instanceof AtomNode) {
AtomNode cloneNode = (AtomNode) node;
IAtom atom = cloneNode.atom;
AtomNode an = dfs.nodes.get(atom);
an.state = cloneNode.state;
an.rings = cloneNode.rings;
an.sortLink = cloneNode.sortLink;
dfs.path.add(an);
} else {
dfs.path.add(new TextNode(((TextNode) node).txt));
}
}
dfs.ringNumber = bestClone.ringNumber;
}
}
use of org.openscience.cdk.interfaces.IAtom 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);
}
Aggregations