Skip to content

Instantly share code, notes, and snippets.

The lyf so short, the craft so long to lerne.
-- Chaucer
def sdfsingledata(filename, data):
if filename.endswith(".gz"):
input = gzip.open(filename, "r")
else:
input = open(filename, "r")
fieldname = "> <%s>\n" % data
for line in input:
if line == fieldname:
line = input.next().strip()
yield line
# Find errors with Implicit Hs
import pybel
import glob
sdfs = glob.glob("C:\Tools\openbabel\PubChem3D\*.sdf")
print sdfs
for sdf in sdfs:
@baoilleach
baoilleach / gist:663914
Created November 5, 2010 10:10
Substructure benchmark
import time
import pybel
ob = pybel.ob
molecules = list(pybel.readfile("sdf", "pubchem_416_benzenes.sdf"))
t = time.time()
query = ob.CompileSmilesQuery("c1ccccc1")
@baoilleach
baoilleach / gist:706453
Created November 19, 2010 12:25
Plot PES from Firefly
from pylab import *
inputfile = open("tmp3.txt", "r")
for line in inputfile:
if line.startswith(" ENERGY DELTA MAP(S) (W.R. TO THE LOWEST FOUND)"):
break
blank = inputfile.next()
dash = inputfile.next()
@baoilleach
baoilleach / gist:723858
Created December 1, 2010 17:30
Printing Springer PDFs
Use "Fit to Printable Area", in combination with 2 pages per sheet. The default setting is "Shrink to Printable Area".
@baoilleach
baoilleach / dodgywedge.py
Created December 8, 2010 10:26
Identify inter-chiralcenter stereobonds in 2D MOL files
import pybel
def dodgywedge(sdffile):
tot = probs = potential_probs = 0
for mol in pybel.readfile("sdf", sdffile):
tot += 1
facade = pybel.ob.OBStereoFacade(mol.OBMol)
tetcenters = [atom.OBAtom for atom in mol
if facade.HasTetrahedralStereo(atom.OBAtom.GetId())]
for idx, atom_a in enumerate(tetcenters[:-1]):
@baoilleach
baoilleach / gist:771081
Created January 8, 2011 19:31
extconf.rb
Here's part of extconf.rb from OB after some edits to add support for --prefix. Unfortunately, this doesn't work (see discussion of mkmf2 which tries to fix some of these problems)
require 'getoptlong'
makeopts = {}
opts = GetoptLong.new(["--prefix", "-p", GetoptLong::OPTIONAL_ARGUMENT],
["--with-openbabel-lib", "-L", GetoptLong::OPTIONAL_ARGUMENT],
["--with-openbabel-include", "-I", GetoptLong::OPTIONAL_ARGUMENT]
).each{|o, a| makeopts[o[%r/[^-].*/]] = a}
prefix = makeopts.delete('prefix') || nil
oblib = makeopts.delete('with-openbabel-lib') || nil
@baoilleach
baoilleach / kinect.py
Created January 15, 2011 16:01
This file makes Jens happy because it allows Avogadro to be controlled by kinect...almost
import os
from PyQt4.QtCore import *
from PyQt4.QtGui import *
##import sys
##sys.path.append("C:\\Python26\\Lib\\site-packages")
##sys.path.append("C:\\Python26\\lib")
import Avogadro as avo
@baoilleach
baoilleach / avogadropainter.py
Created January 19, 2011 17:06
Python Painter for Avogadro
from PyQt4.Qt import *
import Avogadro
class Engine(QObject):
# declare the changed() signal
__pyqtSignals__ = ("changed()",)
# constructor
def __init__(self):