This is a read-only mirror of pymolwiki.org

Difference between revisions of "LatticeGenerator"

From PyMOL Wiki
Jump to navigation Jump to search
(created)
 
m (1 revision)
 
(No difference)

Latest revision as of 01:47, 28 March 2014

This is a simple script to generate a repeating atom lattice. It just writes atoms in PDB format, and PyMOL will automatically connect adjacent atoms when loading the PDB file. You may adjust the c and/or x_shift, y_shift arrays to obtain different geometries, and the number of iterations in the loops to adjust the lattice size.

See also the thread on pymol-users mailing list.

from numpy import array

# coordinates of the repeating unit (from cyclohexane)
c = array([[ 0.064,   2.851,  -1.085 ],
           [ 0.260,   1.969,   0.159 ]])
x_shift = array([ 1.67441517, -0.91605961,  1.66504574])
y_shift = array([-0.69477826, -0.40578592,  2.40198410])

# template string for PDB hetatom line
s = 'HETATM %4d  C03 UNK     1    %8.3f%8.3f%8.3f  0.00  0.00           C  '

out = open('lattice.pdb', 'w')

i = 0
for x in range(10):
    for y in range(10):
        for v in (c + (x-y/2) * x_shift + y * y_shift):
            i += 1
            print >> out, s % (i, v[0], v[1], v[2])

out.close()

try:
    from pymol import cmd
    cmd.load('lattice.pdb')
except ImportError:
    print 'Please load lattice.pdb with PyMOL'