#! /usr/bin/python -t # _*_ coding: iso-8859-1 _*_ # Last edited on 2013-02-20 01:07:16 by stolfilocal PROG_NAME = __file__[len(__file__)-3] PROG_DESC = "Outputs an SVG 'roadkill' diagram for said molecule" PROG_VERS = "1.0" PROG_COPYRIGHT = "Copyright © 2010-02-19 by the State University of Campinas (UNICAMP)" import sys import os import re import math; from math import sqrt,sin,cos,pi sys.path[1:0] = [ '.', '..', sys.path[0] + '/../lib', os.path.expandvars('${STOLFIHOME}/lib') ] # sys.stderr.write(re.sub('[,]', ',\n', "%s: path = %r\n" % (PROG_NAME, sys.path))); import rn import mformula; from mformula import MFormula import mformula_oxocarbon; from mformula_oxocarbon import build_formula_COOH; import mformula_svg; from mformula_svg import MFormula_SVG import mformula_args; import argparser PROG_HELP = \ PROG_NAME + " \\\n" \ + argparser.help_info_HELP + " \\\n" \ " > {FIGURE}.svg" PROG_INFO = \ "NAME\n" \ " " + PROG_NAME + " - " + PROG_DESC + ".\n" \ "\n" \ "DESCRIPTION\n" \ " " + PROG_HELP + ".\n" \ "\n" \ "DOCUMENTATION OPTIONS\n" \ + argparser.help_info_INFO + "\n" \ "\n" \ "AUTHOR\n" \ " Created 2010-02-19 by Jorge Stolfi, IC-UNICAMP.\n" \ "\n" \ "MODIFICATION HISTORY\n" \ " 2010-02-19 by J. Stolfi, IC-UNICAMP: created.\n" \ "\n" \ "WARRANTY\n" \ " " + argparser.help_info_NO_WARRANTY + "\n" \ "\n" \ "RIGHTS\n" \ " " + PROG_COPYRIGHT + ".\n" \ "\n" \ " " + argparser.help_info_STANDARD_RIGHTS style = mformula_args.parse(None); def build_formula() : fm = MFormula(style); fh = build_formula_half(); k0 = fm.add_subformula(fh, 0, 0, [0,0]); # Left half k1 = fm.add_subformula(fh, 1, 0, [0,0]); # Right half cv = 2.0; # Valence of bond from middle C to keto O. cb = fh.bond_length(cv); # Relative length of bond from middle C to keto O. p3 = [0,0]; # Middle carbon. p4 = rn.add(p3, rn.scale(cb, [00, -1.0])); # Keto oxygen. k3 = fm.add_atom("C", p3, 0,0); k4 = fm.add_atom("O", p4, 0,0); fm.add_bond(k0+0,k3,1.0); fm.add_bond(k1+0,k3,1.0); fm.add_bond(k3,k4,cv); return fm; def build_formula_half() : fh = MFormula(style); Ac = 30; # Angle of carboxyls with horizontal (degrees). Ao = 120; # Opening angle of oxygens in carboxyls (degrees). Ah = Ao/2.0 - Ac; # Bend angle of C-O-H to keep the OH horizontal (degrees). c30 = cos(30*pi/180); s30 = sin(30*pi/180); av = 1.0; # Valence of bond from end C to middle C. ab = fh.bond_length(av); # Relative length of bond from end C to middle C. # Atom centers: p0 = [+c30*ab,+s30*ab]; # Carboxyl carbon. fg = build_formula_COOH(style, Ao,Ah, 0); k0 = fh.add_subformula(fg, 0, Ac, p0); return fh; fm = build_formula(); svg = MFormula_SVG(fm,0); svg.standard_elem_style_1(); svg.output_figure();