use of org.openscience.cdk.interfaces.IAtom in project Smiles2Monomers by yoann-dufresne.
the class SmilesConverter method transform.
public Molecule transform(String smiles, boolean addHydrogens, boolean calculateCoordinate, boolean expliciteHydrogens) throws InvalidSmilesException {
Molecule imol = null;
try {
imol = new Molecule(sp.parseSmiles(smiles));
// Add hydrogens
if (addHydrogens) {
CDKHydrogenAdder adder = CDKHydrogenAdder.getInstance(imol.getBuilder());
try {
adder.addImplicitHydrogens(imol);
if (expliciteHydrogens)
AtomContainerManipulator.convertImplicitToExplicitHydrogens(imol);
} catch (CDKException e) {
e.printStackTrace();
}
} else {
for (IAtom a : imol.atoms()) a.setImplicitHydrogenCount(0);
if (!expliciteHydrogens)
imol = new Molecule(AtomContainerManipulator.removeHydrogens(imol));
}
if (calculateCoordinate) {
StructureDiagramGenerator sdg = new StructureDiagramGenerator(imol);
try {
sdg.generateCoordinates();
} catch (CDKException e) {
System.err.println(smiles);
e.printStackTrace();
}
imol = new Molecule(sdg.getMolecule());
}
} catch (InvalidSmilesException e) {
throw e;
}
return imol;
}
use of org.openscience.cdk.interfaces.IAtom in project Smiles2Monomers by yoann-dufresne.
the class Coverage method getCoverageRatio.
public double getCoverageRatio() {
if (!this.alreadyCalculate)
this.calculateGreedyCoverage();
int coveredAtoms = 0;
for (Match match : this.usedMatches) coveredAtoms += match.getAtoms().size();
int pepAtoms = 0;
for (@SuppressWarnings("unused") IAtom a : this.co.getMolecule().atoms()) pepAtoms++;
double ratio = new Double(coveredAtoms) / new Double(pepAtoms);
return ratio;
}
use of org.openscience.cdk.interfaces.IAtom in project Smiles2Monomers by yoann-dufresne.
the class IsomorphismTests method MappingTest.
@Test
public void MappingTest() {
List<MappedChain> mbs = Isomorphism.searchFromPreviousMapping(this.mb0, this.ext1, MatchingType.STRONG);
boolean isGood = true;
for (MappedChain mb : mbs) {
List<MappedChain> extendedMbs = Isomorphism.searchFromPreviousMapping(mb, this.ext2, MatchingType.STRONG);
MappedChain newMb = extendedMbs.get(0);
IMolecule mol = mb.getChemObject().getMolecule();
IAtom newA = (mol.getAtom(newMb.getAtomsMapping().get(2)));
if (!(// Same first atom
(newMb.getAtomsMapping().get(0) == mb.getAtomsMapping().get(0)) && // Same second atom
(newMb.getAtomsMapping().get(1) == mb.getAtomsMapping().get(1)) && // Extended by C atom
(newA.getSymbol().equals("C"))))
isGood = false;
}
Assert.assertTrue(isGood);
}
use of org.openscience.cdk.interfaces.IAtom in project Smiles2Monomers by yoann-dufresne.
the class ContractedGraph method addUncoveredVerticies.
// Create nodes not covered
private void addUncoveredVerticies(IMolecule mol) {
for (IAtom atom : mol.atoms()) {
int idx = mol.getAtomNumber(atom);
if (!this.verticiesOfatoms.keySet().contains(idx)) {
Vertex v = new Vertex();
v.id = "?";
v.vertices.add(idx);
this.addVertex(v);
this.verticiesOfatoms.put(idx, v);
}
}
}
use of org.openscience.cdk.interfaces.IAtom in project Smiles2Monomers by yoann-dufresne.
the class ContractedGraph method createLinks.
// Create links between contracted and unknown nodes
private void createLinks(IMolecule mol) {
this.removeAllEdges(this.edgeSet());
for (Object o : this.vertexSet()) {
Vertex v = (Vertex) o;
for (int idx : v.vertices) {
IAtom a = mol.getAtom(idx);
List<IAtom> neighbors = mol.getConnectedAtomsList(a);
for (IAtom n : neighbors) {
int aIdx = mol.getAtomNumber(n);
if (!v.vertices.contains(aIdx)) {
// Base edge
Vertex vOa = this.verticiesOfatoms.get(aIdx);
String l0 = "";
String l1 = "";
// Labels
if (v.kind.containsKey(idx))
l0 = v.kind.get(idx).getName();
if (vOa.kind.containsKey(aIdx))
l1 = vOa.kind.get(aIdx).getName();
LabeledEdge edge = new LabeledEdge(v, vOa, l0, l1);
this.addEdge(edge);
}
}
}
}
}
Aggregations