From: Prof. Eddie (
Date: Tue Sep 29 2015 - 12:59:40 CDT

I am trying to write a function that will take in a psf and pdb and then
displace them. Doing this multiple times should make a periodic system of
identical ligands.

proc create_lc_system {masterpsffile masterpdbfile N } {
  set dx 20.0;

  set segnum 1

  for {set i -$N} {$i <=$N } {incr i} {
    #read the master file
     readpsf $masterpsffile pdb $masterpdbfile

    #load the molecule
    mol load psf $masterpsffile pdb $masterpdbfile

    #only move the newly loaded ligand, so give it a unique segid
    set newseg [atomselect top all]

    set newsegname "P$segnum"
    set newsegid "P$segnum"

    $newseg set segname $newsegname
    $newseg set segid $newsegname

    set atomstomove [atomselect top "segname $newsegname"]

     foreach atom [$atomstomove get {segid resid name x y z}] {
       foreach {segid resid name x y z} $atom {break}
       set newx [expr $x + $i*$dx]
       coord $segid $resid $name [list $newx $y $z]
    incr segnum

  writepdb lc_system_${N}.pdb
  writepsf lc_system_${N}.psf
  mol load psf lc_system_${N}.psf pdb lc_system_${N}.pdb

When I run it, the script fails on the coord command:
psfgen) no segment P1
ERROR: failed on coord
MOLECULE DESTROYED BY FATAL ERROR! Use resetpsf to start over.

If I use the vmd graphical representations or just picking atoms I see the
segnameand id has been changed. Anyone know what I am doing incorrectly?

Edward Ackad, Ph.D <>
Assistant Professor of Physics
Computational Nanophotonics
Southern Illinois University Edwardsville
(618) 650-2390