Git Product home page Git Product logo

xyz2svg's Introduction

xyz2svg

Lightweight script to make vector images of molecules

Requirements

  • python>=3.6
  • briling/v or something capable of printing atom positions and connectivity

Basic usage

v mol/caffeine.xyz | ./mol2svg.py > caffeine.svg

Open an xyz file with v, rotate the molecule as you like and press p, then x to exit

vector balls-and-sticks image of caffeine

Input file modification

For a water dimer

v mol/kj-H2O_1--H3O+.xyz > input/kj-H2O_1--H3O+.inp

prints

atom   8   -1.1697501   -0.1527130    0.0202511
atom   1   -1.8639331    0.4812310   -0.1588469
atom   1   -1.6335311   -0.9640680    0.2263131
atom   8    1.1960949    0.3707430   -0.0773079
atom   1    0.2351029    0.2036530   -0.0496909
atom   1    1.6046709    0.2360230    0.7985351
atom   1    1.6313459   -0.1748690   -0.7592539
bond   1   2
bond   1   3
bond   4   5
bond   4   6
bond   4   7

This file contains atomic numbers and coordinates in Å and list of bonds (base 1). We can add a hydrogen bond between atoms 1–5:

bond 1 5 -1

(see input/kj-H2O_1--H3O+.inp). Then

./mol2svg.py < input/kj-H2O_1--H3O+.inp > figures/kj-H2O_1--H3O+.svg

gives
vector balls-and-sticks image of a water dimer

One can also add (positive or negative) bond orders (input/caffeine_v2.inp): vector balls-and-sticks image of caffeine with double bonds

Drawing options

Run

./mol2svg.py --help

to get help:

  --num                                                 add atom numbers
  --canvas-size CANVAS_SIZE                             basic canvas size (default 80)
  -wa ATOM_BORDER, --atom-border ATOM_BORDER            atom border width (default 5.0)
  -wb BOND_WIDTH, --bond-width BOND_WIDTH               bond width (default 5.0)
  -db BOND_DISTANCE, --bond-distance BOND_DISTANCE      line distance in multiple bonds (default 0.05)
  -rs ATOM_SIZE, --atom_size ATOM_SIZE                  scaling factor for atom radii
  -r%d ATOM_%d_RADIUS                                   sets basic radius for a specific element (in Å)
  -g, --gradient                                        fill atoms with radial gradients (pseudo-3D mode)

The same caffeine with options:

./mol2svg.py -rs 3.5 -wa 10 -wb 10 -db 0.1 < input/caffeine_v2.inp > figures/caffeine_v3.svg

vector balls-and-sticks image of caffeine with double bonds and looks nice

@iribirii's pseudo-3D mode:

./mol2svg.py -rs 3.5 -wb 10 -g < input/caffeine.inp > figures/caffeine_v4.svg

vector balls-and-sticks image of caffeine with a pseudo 3D effect

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.