use of org.openscience.cdk.Molecule 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;
}
use of org.openscience.cdk.Molecule in project Smiles2Monomers by yoann-dufresne.
the class MonomericSpliting method computeCoverage.
/**
* Calculate an object Coverage with all matches from families.
* @param pep Peptide to match
*/
public void computeCoverage(Polymer pep) {
this.coverage = new Coverage(pep);
this.matcher.setChemicalObject(pep);
Isomorphism.setMappingStorage(true);
// Step 1 : Strict Matching
if (verbose) {
System.out.println("+Strict matching");
System.out.println("++Search residues");
}
this.matchAllFamilies(MatchingType.STRONG);
double ratio = this.coverage.getCoverageRatio();
if (ratio < 1.0) {
if (verbose)
System.out.println("++Modulation");
this.coverage = this.modulation.modulate(this.coverage);
}
Coverage save = this.coverage.clone();
// conditions to go to light matching
if (!this.allowLightMatchs || ratio == 1.0) {
Isomorphism.setMappingStorage(false);
return;
}
// TODO : Why if/else ?
if (this.condition == null)
this.condition = new ExtendsNTimes(this.retry);
else
this.condition.init();
this.remover.init();
// Successive matchings
int depth = 0;
while (this.coverage.getCoverageRatio() < 1.0 && this.condition.toContinue(this.coverage)) {
depth++;
// Contract the atomic graph to monomeric graph
ContractedGraph contracted = new ContractedGraph(this.coverage);
// Remove monomers from the current solution to try with other matching strategy
this.remover.remove(this.coverage, contracted);
// Create a masked molecule to only search on free polymer areas
Molecule mol = DeepenMatcher.mask(this.coverage);
this.coverage.setCurrentMaskedMol(mol);
OtherChemicalObject tmp = new OtherChemicalObject(mol);
this.matcher.setChemicalObject(tmp);
if (verbose) {
System.out.println("+Light matching, depth " + depth);
System.out.println("++Search residues");
}
// Compute for all families with ligth matching
this.matchAllFamilies(MatchingType.LIGHT);
// Re-compute coverage
this.coverage.calculateGreedyCoverage();
if (this.coverage.getCoverageRatio() < 1.0) {
if (verbose)
System.out.println("++Modulation");
this.coverage = this.modulation.modulate(this.coverage);
}
if (this.coverage.getCoverageRatio() > save.getCoverageRatio())
save = this.coverage.clone();
this.remover.nextLevel();
}
Isomorphism.setMappingStorage(false);
if (save.getCoverageRatio() > this.coverage.getCoverageRatio())
this.coverage = save;
}
use of org.openscience.cdk.Molecule in project Smiles2Monomers by yoann-dufresne.
the class PictureGenerator method transform.
/**/
public Molecule transform(String smiles) throws InvalidSmilesException {
Molecule imol = null;
imol = new Molecule(this.sp.parseSmiles(smiles));
for (IAtom a : imol.atoms()) a.setImplicitHydrogenCount(0);
StructureDiagramGenerator sdg = new StructureDiagramGenerator(imol);
try {
sdg.generateCoordinates();
} catch (CDKException e) {
System.err.println(smiles);
e.printStackTrace();
}
imol = new Molecule(sdg.getMolecule());
return imol;
}
use of org.openscience.cdk.Molecule 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.Molecule in project Smiles2Monomers by yoann-dufresne.
the class DeepenMatcher method mask.
/**
* Create a new molecule without covered atoms
*/
public static Molecule mask(Coverage coverage) {
Molecule covMol = coverage.getChemicalObject().getMolecule();
Molecule mol = new Molecule();
List<Integer> coveredIdxs = DeepenMatcher.calculateCoveredAtoms(coverage);
for (IAtom atom : covMol.atoms()) if (!coveredIdxs.contains(covMol.getAtomNumber(atom)))
mol.addAtom(atom);
HashSet<IBond> bonds = new HashSet<>();
for (IAtom atom : mol.atoms()) {
for (IBond bond : covMol.getConnectedBondsList(atom)) if (mol.contains(bond.getAtom(0)) && mol.contains(bond.getAtom(1))) {
if (!bonds.contains(bond)) {
mol.addBond(bond);
bonds.add(bond);
}
}
}
return mol;
}
Aggregations