11
$\begingroup$

I am using ASE to write an xyz file. Each frame in the file has a different PBC (periodic boundary condition). Currently, a frame starts like this:

192
Lattice="23.46511 0.0 0.0 0.0 23.46511 0.0 0.0 0.0 23.46511" Properties=species:S:1:pos:R:3:force:R:3 TotEnergy=-1103.24236 cutoff=-1.0 nneightol=1.2 pbc="T T T"
O       11.72590000      14.59020000       1.86929000      -0.04213780       0.03788820       0.00314949
H       12.69400000      16.13880000       1.25499000      -0.03709700      -0.03453660       0.01566490

The lattice coordinates are what I want to use as the PBC box. However, when I try to visualize this file in VMD, it throws the following error and doesn't show the box:

vmd > pbc box
ERROR) Suspicious pbc side length (a=0.000000 b=0.000000 c=0.000000). Have you forgotten to set the pbc parameters?

What should be done to include a,b,c in the xyz file so that it is compatible with pbc box in VMD?

$\endgroup$
1
  • 2
    $\begingroup$ +1. It's great to see so many people active here during this holiday season, and even at this time (which is well past midnight in my time zone!). I'm surprised you didn't add the ASE tag. I've added it now. Tristan Maxson is a frequent user of this site and is an ASE developer so adding that tag might help. Also we have an ASE chatroom: chat.stackexchange.com/rooms/111469/ase. Like the LAMMPS one, it's not so active yet, but Tristan and I, and some others, have chatted there. If you can write one message there, then it will be good for us to be able to remember your interest in ASE. $\endgroup$ – Nike Dattani Dec 28 '20 at 8:58
10
$\begingroup$

That is a modification of the standard XYZ file format and is called extended XYZ format, and not all programs are compatible with it.

From the VMD Molfile Plugin Documentation page, it looks that VMD is only compatible with standard XYZ format.

Also, take a look at this answer (to another question) about adding PBC info in VMD after loading standard XYZ file.

$\endgroup$
3
  • $\begingroup$ Thank you for your answer. The method I the linked answer isn't really helpful to me since (as mentioned in the question) the PBC constraints are different for each config. $\endgroup$ – fireball.1 Dec 29 '20 at 10:02
  • $\begingroup$ Maybe you can use a loop in order to add the info for each individual XYZ file. $\endgroup$ – Camps Dec 29 '20 at 12:35
  • $\begingroup$ I was not aware that i can parse files and create loops in VMD console. Will try $\endgroup$ – fireball.1 Dec 29 '20 at 13:42
6
$\begingroup$

Camps is correct, VMD cannot directly parse the comment line of an xyz file because the extended ASE format is not recognized. You can, however, use a tcl-script to load the file and parse the comment line yourself. I am no tcl expert but here is an example that works for me:

set filename [lindex $argv 0]
    
# load the coordinates into vmd
mol new $filename waitfor all
    
# open the file to parse the lattice vectors
set file [open $filename]
    
set i 0
    
while {[gets $file line] >= 0} {
  # get the lines containing Lattice="
  if {[regexp {Lattice=\"[ 0-9\.\-eE]*} $line lattice]} {  
    # extract the numbers from the line into v_arr
    set vectors [regexp -all -inline {\S+} [lindex [split $line \"] 1]]
    set j 0     
    foreach v $vectors {
      set v_arr($j) $v
      incr j
    }
    # set the pbc for the i-th frame
    # uncomment the second line if the cell is not orthorhombic
    pbc set "{$v_arr(0) $v_arr(4) $v_arr(8)}" -first $i -last $i
    #pbc set "{{$v_arr(0) $v_arr(1) $v_arr(2)} {$v_arr(3) $v_arr(4) $v_arr(5)} {$v_arr(6) $v_arr(7) $v_arr(8)}}" -namd -first $i -last $i
    incr i
  }
}
    
close $file

Save the code into a file "pbc.tcl". You can then invoke the script by running

vmd -e pbc.tcl -args trajectory.xyz

This will automatically load the coordinates and parse the lattice vectors from trajectory.xyz. The -e flag signals vmd to execute the code within pbc.tcl and passes the -args to the script.

$\endgroup$
4
  • $\begingroup$ The code interpreter does not recognize the escaped " and treats half the code as a string. How can I fix that? $\endgroup$ – Fabian Dec 29 '20 at 13:58
  • 1
    $\begingroup$ I was able to fix the highlighting issue. In these code blocks, you can specify a language at the top to give a hint to the syntax highlighter. Once it knew it was Tcl, it was able to highlight properly. I may have offset some of the indentation while editing, but hopefully the meaning is still clear. $\endgroup$ – Tyberius Dec 29 '20 at 18:41
  • $\begingroup$ Thanks @Tyberius! I did not realize I could do that. $\endgroup$ – Fabian Dec 29 '20 at 21:30
  • 1
    $\begingroup$ @Fabian For a full breakdown on post editing capabilities, check out the Advanced Editing page from the Help Center. $\endgroup$ – TylerH Dec 30 '20 at 14:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.