From: Ackad, Edward (eackad_at_siue.edu)
Date: Sat Jul 22 2023 - 09:00:19 CDT

Hi all,
I've been having trouble getting a script to work for the following case. I have two compounds in different solvents. I want to see their interaction over time so I need to wrap them in the box. Here is the script I've been trying to get working but it complains about the pdb write or it ends up breaking all the bonds and completely distorting the compounds. I try writing the pdb twice but it seems if there are too many frames then the first pdb write gives:
Info) Opened coordinate file A.pdbA.pdb for writing.
PDB WRITE ERROR: Position, occupancy, or b-factor (beta) for atom 14
                 cannot be written in PDB format.
                 File will be truncated.
ERROR) write_timestep returned nonzero

Script:

set pdbs {"A.pdb" "B.pdb"}
set xtcs {"A.xtc" "B.xtc"}

# join the molecules and get rid of the solvent
for {set mymol 0} {$mymol < 2 } { incr mymol } {
    set nameis [lindex $pdbs $mymol]
    set namextc [lindex $xtcs $mymol]
    mol new "$nameis" type pdb
    mol addfile "$namextc" type xtc first 0 last -1 step 80 filebonds 1 autobonds 1 waitfor all
    puts "Joining: $nameis"
    pbc join residue -first 0 -last 0
    pbc unwrap
    set sel [atomselect top "residue 0 1"]
    $sel writepdb "${nameis}A.pdb"
    puts "Time to animate $nameis 1"
    animate write dcd "${nameis}.dcd" waitfor all sel $sel [molinfo top]
    puts "Time to savepdb $nameis 2"
    set sel2 [atomselect top "residue 0 1" frame 0]
    $sel2 writepdb "${nameis}.pdb"
    puts "done! $nameis"
    mol delete top
}

puts "Starting Wrap"
set outfile [open "status.txt" "w"]
for {set mymol 0} {$mymol < 2 } { incr mymol } {
    set nameis [lindex $pdbs $mymol]
    mol new "${nameis}A.pdb"
    mol addfile "$nameis.dcd" type dcd first 0 last -1 step 1 filebonds 1 autobonds 1 waitfor all
    puts "done loading $nameis dcd"
    set all [atomselect top "all"]
    set cellDims [measure minmax $all]

    set cellLengths [vecsub [lindex $cellDims 1] [lindex $cellDims 0]]
    pbc wrap -all -compound residue -centersel "all" -center com -all
    puts "doing animate"
    puts $outfile "doing animate"
    # Save the wrapped trajectory
    animate write dcd "${nameis}_wrapped.dcd" waitfor all [molinfo top]
    mol delete top
}
close $outfile

Thank you in advance!

_________________________________________________________
Edward Ackad, Ph.D<https://urldefense.com/v3/__http://www.siue.edu/*7Eeackad__;JQ!!DZ3fjg!9LK1oTjo3CyP1NwARoA0Sn1HKwousyqZ6tEyUnIeBIuZvkgZs8U1OtQS0F6R12MmDowyXAlMjGtb1kNaNA$ >
Associate Professor of Physics
Computational Nanophotonics/Biophysics
Southern Illinois University Edwardsville
(618) 650-2390