LatticeGenerator

From PyMOLWiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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
            out.write(s % (i, v[0], v[1], v[2]) + "\n")

out.close()

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