Difference between revisions of "LatticeGenerator"

From PyMOLWiki
Jump to: navigation, search
(created)
 
m (py3)
 
Line 20: Line 20:
 
for x in range(10):
 
for x in range(10):
 
     for y in range(10):
 
     for y in range(10):
         for v in (c + (x-y/2) * x_shift + y * y_shift):
+
         for v in (c + (x-y//2) * x_shift + y * y_shift):
 
             i += 1
 
             i += 1
             print >> out, s % (i, v[0], v[1], v[2])
+
             out.write(s % (i, v[0], v[1], v[2]) + "\n")
  
 
out.close()
 
out.close()
Line 30: Line 30:
 
     cmd.load('lattice.pdb')
 
     cmd.load('lattice.pdb')
 
except ImportError:
 
except ImportError:
     print 'Please load lattice.pdb with PyMOL'
+
     print('Please load lattice.pdb with PyMOL')
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 
[[Category:Script_Library]]
 
[[Category:Script_Library]]

Latest revision as of 09:43, 17 January 2018

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')