Skip to content

Instantly share code, notes, and snippets.

@baoilleach
Created August 28, 2009 10:57
Show Gist options
  • Save baoilleach/176902 to your computer and use it in GitHub Desktop.
Save baoilleach/176902 to your computer and use it in GitHub Desktop.
"""sdfdatareader.py
Super fast skimmer over sdf files just to return the data
fields
"""
def sdf(filename):
input = open(filename, "r")
data = {}
for line in input:
if line.startswith("> <"):
k = line.rstrip()[3:-1]
v = []
line = input.next().strip()
while line:
v.append(line)
line = input.next().strip()
data[k] = "\n".join(v)
elif line.startswith("$$$$"):
yield data
data = {}
if __name__ == "__main__":
filename = r"myfile.sdf"
for mol in sdf(filename):
data = mol
print data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment