Skip to content

Instantly share code, notes, and snippets.

View johnmay's full-sized avatar

John Mayfield johnmay

View GitHub Profile
// compute labelling (others are available)
final long[] labels = Canon.label(m, GraphUtil.toAdjList(m));
IAtom[] atoms = AtomContainerManipulator.getAtomArray(m);
IBond[] bonds = AtomContainerManipulator.getBondArray(m);
// atoms don't know their index
for (int i = 0; i < labels.length; i++)
atoms[i].setProperty("rank", labels);
@johnmay
johnmay / Main.java
Created September 10, 2014 20:40
Hello World no semicolon
public class Main {
public static void main(String[] args) throws Exception {
while(System.out.getClass()
.getMethod("println", String.class)
.invoke(System.out, "Hello world!") != null) {
}
}
}
@johnmay
johnmay / Main.java
Last active August 29, 2015 14:06
Hello World - no dot.
// imports can be inlined but excluded for readability
// import javax.script.SimpleScriptContext;
// import java.io.PrintWriter;
public class Main {
public static void main(String[] args) {
new SimpleScriptContext() {{
new PrintWriter(writer) {{
println("Hello World!");
flush();
Map<AtomPair,IBond> bondMap = new HashMap<>();
for (IBond bond : container.bonds())
bondMap.put(new AtomPair(bond.getAtom(0), bond.getAtom(1)),
bond);
class AtomPair {
IAtom a, b;
AtomPair(IAtom a, IAtom b) {
this.a = a, this.b = b;
IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance();
SmilesParser smipar = new SmilesParser(bldr);
SmilesGenerator smigen = SmilesGenerator.unique();
System.out.println(smigen.create(smipar.parseSmiles("c1cc2c(cc1)cccc2")));
System.out.println(smigen.create(smipar.parseSmiles("C1=CC2=C(C=C1)C=CC=C2")));
System.out.println(smigen.create(smipar.parseSmiles("C=1C=C2C(=CC=1)C=CC=C2")));
System.out.println(smigen.create(smipar.parseSmiles("C1=CC=2C(C=C1)=CC=CC=2")));
static IAtomContainer mykekule(IAtomContainer org) throws Exception {
final IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance();
final SmilesParser smipar = new SmilesParser(bldr);
final SmilesGenerator smigen = SmilesGenerator.unique();
final int n = org.getAtomCount();
int[] ordering = new int[n];
// generate a kekule assignment via SMILES and store the output order (a permutation of
IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance();
SmilesParser smipar = new SmilesParser(bldr);
SmilesGenerator smigen = SmilesGenerator.generic();
System.out.println(smigen.create(mykekule(smipar.parseSmiles("c1cc2c(cc1)cccc2"))));
System.out.println(smigen.create(mykekule(smipar.parseSmiles("C1=CC2=C(C=C1)C=CC=C2"))));
System.out.println(smigen.create(mykekule(smipar.parseSmiles("C=1C=C2C(=CC=1)C=CC=C2"))));
System.out.println(smigen.create(mykekule(smipar.parseSmiles("C1=CC=2C(C=C1)=CC=CC=2"))));
BufferedReader brdr = ...;
// create once and reuse
IChemObjectBuilder bldr = SilentChemObjectBuilder.getInstance();
Aromaticity arom = new Aromaticity(ElectronDonation.daylight(),
Cycles.or(Cycles.all(), Cycles.all(6)));
// SMILES, implicit h already present
SmilesParser smipar = new SmilesParser(bldr);
String line;
@johnmay
johnmay / gist:3139004
Created July 18, 2012 21:24
CDK GeometryTools has2DCoordinates
if (GeometryTools.has2DCoordinates(container)) {
renderer.paint(container, new AWTDrawVisitor(g2), bounds, true);
} else {
// can log or invoke g2.drawString() to display "no coordinates"
}
static int aromStatus(IAtomContainer mol) {
int res = 0;
for (IAtom atom : mol.atoms()) {
if (atom.getImplicitHydrogenCount() == null && atom.getFlag(CDKConstants.ISAROMATIC)) {
// N and P are ambiguous
if (atom.getAtomicNumber() == 7 || atom.getAtomicNumber() == 15)
res = 2;
else if (res < 2)
res = 1;
}