Skip to content

Instantly share code, notes, and snippets.

@baoilleach
Created March 3, 2012 15:54
Show Gist options
  • Save baoilleach/1966793 to your computer and use it in GitHub Desktop.
Save baoilleach/1966793 to your computer and use it in GitHub Desktop.
Modify the SVG output of Open Babel to potentially improve performance (it doesn't really in the end)
inputfile = open("mols_1000.svg", "r")
outputfile = open("tmp.svg", "w")
t = ""
DEFAULT, LINE = range(0, 2)
state = DEFAULT
for line in inputfile:
t = line
if line.startswith("<line x1"):
if state == DEFAULT:
outputfile.write('<g stroke="rgb(0,0,0)" stroke-width="2.0">\n')
state = LINE
broken = line.split()
t = " ".join(broken[:5]) + "/>\n"
else:
if state == LINE:
outputfile.write("</g>\n")
state = DEFAULT
if line.startswith("font-family"):
broken = line.split()
t = " ".join(broken[:1] + ['font-weight="bold"'] + broken[3:]) + "\n"
if line.startswith("<text"):
broken = line.split()
if broken[1].startswith("x="):
t = " ".join(broken[0:4] + broken[6:]) + "\n"
outputfile.write(t)
oldt = t
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment