use of org.openscience.cdk.interfaces.IMolecule in project Smiles2Monomers by yoann-dufresne.
the class SmilesGenerator method createSMILES.
/**
* Generate canonical SMILES from the <code>molecule</code>. This method
* canonicaly lables the molecule but dose not perform any checks on the
* chemical validity of the molecule. This method also takes care of multiple
* molecules.
* IMPORTANT: A precomputed Set of All Rings (SAR) can be passed to this
* SmilesGenerator in order to avoid recomputing it. Use setRings() to
* assign the SAR.
*
* @param molecule The molecule to evaluate.
* @param chiral true=SMILES will be chiral, false=SMILES.
* will not be chiral.
* @param doubleBondConfiguration Should E/Z configurations be read at these positions? If the flag at position X is set to true,
* an E/Z configuration will be written from coordinates around bond X, if false, it will be ignored.
* If flag is true for a bond which does not constitute a valid double bond configuration, it will be
* ignored (meaning setting all to true will create E/Z indication will be pu in the smiles wherever
* possible, but note the coordinates might be arbitrary).
* @exception CDKException At least one atom has no Point2D;
* coordinates are needed for crating the chiral smiles. This excpetion
* can only be thrown if chiral smiles is created, ignore it if you want a
* non-chiral smiles (createSMILES(AtomContainer) does not throw an
* exception).
* @see org.openscience.cdk.graph.invariant.CanonicalLabeler#canonLabel(IAtomContainer)
* @return the SMILES representation of the molecule
*/
public synchronized String createSMILES(IAtomContainer molecule, boolean chiral, boolean[] doubleBondConfiguration) throws CDKException {
IMoleculeSet moleculeSet = ConnectivityChecker.partitionIntoMolecules(molecule);
if (moleculeSet.getMoleculeCount() > 1) {
StringBuffer fullSMILES = new StringBuffer();
for (int i = 0; i < moleculeSet.getAtomContainerCount(); i++) {
IMolecule molPart = moleculeSet.getMolecule(i);
fullSMILES.append(createSMILESWithoutCheckForMultipleMolecules(molPart, chiral, doubleBondConfiguration));
if (i < (moleculeSet.getAtomContainerCount() - 1)) {
// are there more molecules?
fullSMILES.append('.');
}
}
return fullSMILES.toString();
} else {
return (createSMILESWithoutCheckForMultipleMolecules(molecule, chiral, doubleBondConfiguration));
}
}
use of org.openscience.cdk.interfaces.IMolecule 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);
}
use of org.openscience.cdk.interfaces.IMolecule in project Smiles2Monomers by yoann-dufresne.
the class LoadersTests method addaTest.
@Test
public void addaTest() {
String smiles = "CC(C=C(C)C=CC(C(C)C(=O)O)N)C(CC1=CC=CC=C1)OC";
try {
smiles = SmilesConverter.conv.toCanonicalSmiles(smiles);
} catch (InvalidSmilesException e) {
System.err.println("Impossible to parse " + smiles);
}
Monomer adda = new Monomer("Adda", "Adda", smiles);
IMolecule mol = adda.getMolecule();
Assert.assertTrue("O=C(O)C(C)C(N)C=CC(=CC(C)C(OC)Cc1ccccc1)C".equals(SmilesConverter.conv.mol2Smiles(mol)));
}
use of org.openscience.cdk.interfaces.IMolecule in project Smiles2Monomers by yoann-dufresne.
the class PolymersToCanonicalSmiles method modify.
public static void modify(String pepFile) {
// Loading
PolymersJsonLoader pjl = new PolymersJsonLoader(new MonomersDB());
PolymersDB db = pjl.loadFile(pepFile);
// transform all smiles
for (Polymer pep : db.getObjects()) {
IMolecule mol = pep.getMolecule();
String smiles = SmilesConverter.conv.mol2Smiles(mol);
pep.setSmiles(smiles);
}
// Saving
pjl.saveFile(db, pepFile);
}
use of org.openscience.cdk.interfaces.IMolecule in project Smiles2Monomers by yoann-dufresne.
the class PictureCoverageGenerator method createPNG.
public ColorsMap createPNG(Coverage coverage, File outfile) {
ColorsMap coverageColors = new ColorsMap();
AtomColorer ac = this.cag.getColorer();
IMolecule mol = coverage.getMolecule(false);
List<Color> colors = ColorsGenerator.HsbColorsGeneration(coverage.nbMatchesForCoverage());
int i = 0;
for (Match match : coverage.getUsedMatches()) {
Residue res = match.getResidue();
List<Color> matchesColor = coverageColors.containsKey(res) ? coverageColors.get(res) : new ArrayList<Color>();
for (int idx : match.getAtoms()) {
if (!"H".equals(coverage.getMolecule(true).getAtom(idx).getSymbol()))
ac.setColor(mol.getAtom(idx), colors.get(i));
}
matchesColor.add(colors.get(i));
coverageColors.put(res, matchesColor);
i++;
}
this.createPNG(mol, outfile);
ac.resetColors();
return coverageColors;
}
Aggregations