#! /usr/bin/python -t # _*_ coding: iso-8859-1 _*_ # Last edited on 2013-02-20 00:37:17 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 © 2009-07-15 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 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 2009-07-15 by Jorge Stolfi, IC-UNICAMP.\n" \ "\n" \ "MODIFICATION HISTORY\n" \ " 2009-07-15 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() : "Builds the molecule's diagram.\n" \ "\n" \ " Assumes that the cycle is an equilateral triangle" \ " centered at [0,0]." # Build the left half {fh} of the molecule, minus the bridging oxygen: # The carbon is atom zero of {fh}. fh = MFormula(style); c30 = cos(30*pi/180); s30 = sin(30*pi/180); sb = fh.bond_length(1.0); # Relative length of single bonds. db = fh.bond_length(2.0); # Relative length of double bonds. R = sb/2/c30; # Radius of cycle. p0 = rn.scale(R, [-c30, -s30]); # Lower left carbon. p1 = rn.add(p0, rn.scale(db, [-c30, -s30])); # Lower left (carbonyl) oxygen. k0 = fh.add_atom("C", p0, 0,0); k1 = fh.add_atom("O", p1, 0,0); fh.add_bond(k0,k1,2.0); # Take two copies of {fh} and add the epoxy O: fm = MFormula(style); i0 = fm.add_subformula(fh, 0, 0, [0,0]); # Left half i1 = fm.add_subformula(fh, 1, 0, [0,0]); # Right half p3 = [ 0, +R ]; # Top (epoxide) oxygen. k3 = fm.add_atom("O", p3, 0,0); fm.add_bond(i0+0,i1+0,1.0); fm.add_bond(i0+0,k3,1.0); fm.add_bond(i1+0,k3,1.0); return fm; fm = build_formula(); svg = MFormula_SVG(fm,0); svg.standard_elem_style_1(); svg.output_figure();