0
$\begingroup$

So, I've written a short python program simulating diffusion in 2D; in essence each particle is behaving like a random walker. The output is a 3D tensor, which for 4 particles and 10 timesteps, looks like this:

[[[ 0.          0.        ]
  [-0.16043999 -0.9870456 ]
  [-1.09597489 -1.34027986]
  [-2.08225903 -1.17522353]
  [-1.76925893 -0.22547044]
  [-2.01800797 -1.19403841]
  [-2.15515569 -2.18458902]
  [-1.32309938 -1.62989786]
  [-2.27406193 -1.9392039 ]
  [-1.90350731 -1.01039322]]

 [[ 0.          0.        ]
  [-0.6938323  -0.72013662]
  [-0.36299996 -1.66382617]
  [ 0.5186036  -1.19183553]
  [ 0.34714146 -0.20664482]
  [ 1.31071192 -0.47409941]
  [ 2.25711798 -0.1511202 ]
  [ 1.58434992 -0.89097365]
  [ 1.3892911   0.0898179 ]
  [ 0.94147109 -0.80430583]]

 [[ 0.          0.        ]
  [ 0.99886494  0.04763229]
  [ 1.5346788   0.89196842]
  [ 0.81263989  1.58382086]
  [-0.18631285  1.62957497]
  [ 0.75609885  1.96403003]
  [-0.06263107  1.38985122]
  [-0.1323122   0.3922819 ]
  [ 0.8338982   0.13452725]
  [ 1.05742482  1.10922508]]

 [[ 0.          0.        ]
  [ 0.04440308  0.9990137 ]
  [ 0.86574242  0.42857379]
  [ 1.16274132 -0.52630403]
  [ 1.43873896  0.43485428]
  [ 2.10741306 -0.30870133]
  [ 1.74826957  0.62458103]
  [ 1.44620452  1.57786834]
  [ 1.31735411  2.56953238]
  [ 0.73397918  1.75732939]]]

So, each block is 1 particle, the columns are x- and y-coordinates, and the rows display successive timesteps. Now, I would like to plug this in into VMD to visualize the particle trajectories. How should the VMD movie format look?

I thank you all for your help!

$\endgroup$

1 Answer 1

1
$\begingroup$

I'd recommend that you use the XYZ file format. Once you have a XYZ trajectory file, go into VMD, load the molecule by clicking File > New molecule, and display the particles by clicking Graphics > Representations > Drawing methods, then choose Points or VDW, for example.

Here's a quick script to produce the desired output:

def write_xyz(xyz: np.array, filename: str) -> None:
    with open(filename, 'w') as f:
        for j in range(xyz.shape[1]):
            print(f'{xyz.shape[0]}\n', file=f)
            for i in range(xyz.shape[0]):
                print(f'p{i} {xyz[i, j, 0]} {xyz[i, j, 1]} 0', file=f)
$\endgroup$
1
  • 1
    $\begingroup$ Thank you for your answer! It works perfectly! $\endgroup$ Commented Feb 11, 2019 at 21:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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