Drawing molecules with PostScript

Vector graphics are great for illustration purposes. Molecules are made up of atoms linked by bonds. I would like the operations of editing a drawing of a chemical structure to be carried out according to the physical structure of molecules: select an atom, transfer it, rotate a fragment of a molecule, sign ... Almost all visualizers of atomic structures export the view to a raster, which complicates the preparation of illustrations. In this post, I'll explain how to render 3D structures in vector format, and how PostScript can help you with this .





Instead of a pretty bitmap image (left), we get a vintage illustration (right).
Instead of a pretty bitmap image (left), we get a vintage illustration (right).

Quite a lot of programs are able to export structure to vector graphics: SVG, PDF, EPS. However, this is often done only formally - the resulting images consist of many primitives, it is almost impossible to disassemble them by atoms and bonds. The size of such a vector file is also large, in a word, it's a disaster. Of the many molecular constructors, only two satisfy the quality of the vector image code : GaussView and Molden . The latter program is available to everyone, so the examples are built with its help, however, all the recipes below are applicable (with some modifications) to vector illustrations made by GaussView. So Molden!





Molden
Molden

, PostScript.





PostScript

:





%!PS-Adobe-2.0 EPSF-2.0
%%Title: Molden
%%For: Schaft
%%Creator: Drs G Schaftenaar
%%DocumentFonts: Courier
%%Pages (atend)
%%BoundingBox: 0 0 612 792
%%EndComments
%
%###### User Preferences ############
%
%---- SIZE AND ORIENTATION OF THE PLOT ---
%
/size    {  0.24 } def
%---- These number can be negative -------
/originx {  39.0 } def
/originy { 753.0 } def
/angle   { -90.0 } def
%For Portrait use
%/originx { 40.0 } def
%/originy { 240.0 } def
%/angle   { 0.0 } def
%and BoundingBox: 25 255 535 765
      
      



- \doatom



, - \dorod



. Molden.





%---- Include Tabel & Logo, Fontsize -----
/tabel {true} def
/titleandlogo {true} def %   false!
      
      



, 4082 . .





4082 primitives
4082

.





%---- SET BOND RENDERING:  ---------------
%---- shadedrod, whiterod, blackrod  -----
%
/doatom { dosketchysmoothatom } def 
/dorod  { sketchyshadedrod }    def
%
%   ( )
/dosketchysmoothatom  %   doatom
{ gsave
  rx ry translate
  90 -15 1 %    90 1 1 -   
  { gsave
    dup cos hue exch satu exch sethsbcolor sin dup scale
    newpath
    0 0 rad 0 360 arc
    closepath fill grestore } for
    grestore } def
/sketchyshadedrod
{ gsave
  x1 y1 translate
  x2 x1 neg add
  y2 y1 neg add
  {atan neg rotate} stopped not {
  85 -15 0 %  87 -3 0 -   
  {dup
  gsave
  newpath
   cos 1.0 cosb 0.5 mul neg add mul
   hue exch satu exch sethsbcolor
   sin 1.0 scale
   1 cosb scale
   0 0 hd 0 180 arcn
   x2 x1 neg add dup mul
   y2 y1 neg add dup mul
   add sqrt
  0 cosb eq {/cosb 1.0 def} if 0 exch cosb div translate
   0 0 hd 180 360 arc
  closepath fill
  grestore } for
  } if
  grestore } def
      
      



There are already 410 primitives instead of 4082.
410 4082.

!





/doatom { docirclecoloratom } def
/dorod { dostick } def

%  ,   ,  
/stickwidth {16} def
/stickgreycolor  {0} def
/strokelinewidth {4} def

/docirclecoloratom
{ gsave
    strokelinewidth setlinewidth
    rx ry translate
    newpath 0 0 rad 0 360 arc closepath
    gsave
    hue satu 1.0 sethsbcolor fill
    grestore
    stroke
    0 0 rad 0.75 mul -60 0 arc
    stroke
    grestore
} def
%  dostick   Molden
      
      



:





, . - 3 . , , . - . .





/docircleatom
{ gsave
    strokelinewidth setlinewidth
    rx ry translate
    newpath 0 0 rad 0 360 arc closepath
    gsave
    1 setgray fill
    grestore
    stroke
    gsave
    1.00 0.55 scale
    0 0 rad 0 180 arc
    stroke
    grestore
    0.55 1.00 scale
    0 0 rad -90 90 arcn
    stroke
    grestore
} def
      
      



This code will radically reduce the drawing to black and white. As in old books.





I added a signature - the length of the hydrogen bond.
I added a signature - the length of the hydrogen bond.

Conclusion

PostScript is surprisingly good at creating illustrations. It's easy to learn. In this post, I gave a way to do simple, but sometimes very, very necessary things when preparing a publication or poster for a conference. However, you can go further! I highly recommend the book Mathematical Illustrations .








All Articles