Skip to content

Instantly share code, notes, and snippets.

@johnmay
Created January 3, 2017 12:49
Show Gist options
  • Save johnmay/9d144ccf047457012222614a15909abb to your computer and use it in GitHub Desktop.
Save johnmay/9d144ccf047457012222614a15909abb to your computer and use it in GitHub Desktop.
public class Main {
public static void main(String[] args) throws CDKException, IOException {
String smi = "C1[C@H]([C@@H](OC2=CC(=CC(=C21)O)O)*)O |$;;;;;;;;;;;;_AP1$|";
SmilesParser smipar = new SmilesParser(SilentChemObjectBuilder.getInstance());
IAtomContainer mol = smipar.parseSmiles(smi);
// atom indexes to highlight
int[] idxs = new int[]{3,4,5,9};
boolean outgoing = true;
Set<IAtom> atomHighlight = new HashSet<>();
Set<IBond> bondHighlight = new HashSet<>();
Set<IAtom> atomMask = new HashSet<>();
for (int idx : idxs)
atomHighlight.add(mol.getAtom(idx));
for (IAtom atom : atomHighlight) {
if (outgoing) {
bondHighlight.addAll(mol.getConnectedBondsList(atom));
} else {
for (IBond bond : mol.getConnectedBondsList(atom)) {
if (atomHighlight.contains(bond.getConnectedAtom(atom)))
bondHighlight.add(bond);
}
}
}
if (outgoing) {
for (IBond bond : bondHighlight) {
IAtom beg = bond.getAtom(0);
IAtom end = bond.getAtom(1);
if (!atomHighlight.contains(beg))
atomMask.add(beg);
if (!atomHighlight.contains(end))
atomMask.add(end);
}
}
DepictionGenerator dg = new DepictionGenerator();
dg = dg.withSize(250, 250);
dg = dg.withOuterGlowHighlight();
dg = dg.withHighlight(atomHighlight, new Color(0xff9999))
.withHighlight(bondHighlight, new Color(0xff9999))
.withHighlight(atomMask, Color.WHITE);
dg.depict(mol).writeTo("~/tmp.png");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment