Skip to content

Instantly share code, notes, and snippets.

View johnmay's full-sized avatar

John Mayfield johnmay

View GitHub Profile
@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"
}
@johnmay
johnmay / gist:3156215
Created July 21, 2012 15:52
UniversalIsomorphismTester with custom a atom matcher
// creating the custom matcher
IAtomMatcher matcher = and(SymbolMatcher.class, ChargeMatcher.class);
if(UniversalIsomorphismTester.isIsomorph(container1, container2, matcher)){
// atoms match charge and symbol
}
@johnmay
johnmay / gist:3156220
Created July 21, 2012 15:53
Creating a custom matcher
new AbstractAtomMatcher(){
@Override
public Object getAttribute(IAtom atom) {
return atom.getProperty("my.custom.property");
}
};
@johnmay
johnmay / gist:3156221
Created July 21, 2012 15:53
Creating a custom matcher
new AbstractAtomMatcher(){
@Override
public Object getAttribute(IAtom atom) {
return atom.getProperty("stereo.descriptor");
}
};
@johnmay
johnmay / gist:3193378
Created July 28, 2012 13:22
IMultiOrderQueryBond
public interface IMultiOrderQueryBond extends IQueryBond {
/**
* Access the alternate bond order
*/
public IBond.Order getAuxiliaryOrder();
/**
* Flips the bond primary and auxiliary orders
*/
@johnmay
johnmay / gist:3200817
Created July 29, 2012 18:20
CDK UIT Self Match
IAtom atom = g1.getAtom(0);
// ...
String atomSymbol = atom.getSymbol();
return g1.getAtom(0).getSymbol().equals(atomSymbol);
@johnmay
johnmay / gist:3201564
Created July 29, 2012 20:05
Creating a custom matcher
new AbstractAtomMatcher(){
@Override
public boolean matchers(IAtom query, IAtom subject) {
Object descriptor1 = query.getProperty("stereo.descriptor");
Object descriptor2 = subject.getProperty("stereo.descriptor");
return descriptor1 != null ? descriptor1.equals(descriptor2) : descriptor2 == null;
}
};
@johnmay
johnmay / gist:3360086
Created August 15, 2012 13:22
CDK Bond Stereo reading from CML
} else if ("bondStereo".equals(name)) {
for (int i = 0; i < atts.getLength(); i++) {
if (atts.getQName(i).equals("dictRef")) {
if (atts.getValue(i).startsWith("cml:"))
bondStereo.add(atts.getValue(i).substring(4));
stereoGiven=true;
}
}
}
@johnmay
johnmay / gist:3360099
Created August 15, 2012 13:25
CML bond stereo
<!-- CDK expects -->
<bond atomRefs2="a2 a4" order="1">
<bondStereo dictRef="cml:W"/>
</bond>
<!-- Normally my files have this -->
<bond atomRefs2="a2 a4" order="1">
<bondStereo>W</bondStereo>
</bond>
@johnmay
johnmay / gist:3416581
Created August 21, 2012 15:29
CDK Highlight
public void generateImageWithBondsHighlighted() throws Exception {
IAtomContainer molecule = MoleculeFactory.makeAdenine();
IAtomContainer selectionMolecule = molecule.getBuilder().newInstance(IAtomContainer.class);
for (int i = 0; i < 3; i++) {
selectionMolecule.addBond(molecule.getBond(i));
}
AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule);