#! /usr/bin/python -t # _*_ coding: iso-8859-1 _*_ # Last edited on 2013-02-20 01:06:41 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); fs = build_formula_sixth(); k0 = fm.add_subformula(fs, 0, 0, [0,0]); k1 = fm.add_subformula(fs, 0, 60, [0,0]); k2 = fm.add_subformula(fs, 0, 120, [0,0]); k3 = fm.add_subformula(fs, 0, 180, [0,0]); k4 = fm.add_subformula(fs, 0, 240, [0,0]); k5 = fm.add_subformula(fs, 0, 300, [0,0]); fm.add_bond(k0+0,k1+0,1.5); fm.add_bond(k1+0,k2+0,1.5); fm.add_bond(k2+0,k3+0,1.5); fm.add_bond(k3+0,k4+0,1.5); fm.add_bond(k4+0,k5+0,1.5); fm.add_bond(k5+0,k0+0,1.5); return fm; def build_formula_sixth() : "Builds 1/6 of the molecule (one carbon and one carboxyl) pointing horizontally." fs = MFormula(style); Ac = 0; # Angle of carboxyl with horizontal (degrees). Ao = 90; # Opening angle of oxygens in carboxyl (degrees). Ah = Ao/2.0 - Ac; # Bend angle of C-O-H to keep the OH horizontal (degrees). cb = fs.bond_length(1.5); # Length of aromatic bonds. ub = fs.bond_length(2.0); # Relative length of single bonds. # Assume that the benzene ring stays hexagonal: R = cb; # Radius of benzene ring. c30 = cos(30*pi/180); s30 = sin(30*pi/180); p0 = [+1*R, 00*R]; # A carbon of benzene. p1 = rn.add(p0, rn.scale(ub, [+1, 00])); # Carbon of carboxyl k0 = fs.add_atom("C", p0, 0,0); fg = build_formula_COOH(style, Ao,Ah, 0); k1 = fs.add_subformula(fg, 0, Ac, p1); fs.add_bond(k0,k1,1.0); return fs; fm = build_formula(); svg = MFormula_SVG(fm,0); svg.standard_elem_style_1(); svg.output_figure();