5
$\begingroup$

I want to visualize an MD trajectory produced with ASE.

  • ase.visualize.view produces an output for atoms and trajectories. I am not able to show the bonds between atoms.
  • For atoms, I can use this in my jupyter notebook, which gives me an ok 3D representation:
from ase.visualize import view
view(atoms, viewer='x3d')
  • For trajectories, I use this, which pops up a 2D representation and is very scarce (no bonds, no cell...):
read_traj = ase.io.trajectory.TrajectoryReader(traj_file)
view(read_traj)
  • eventually, I would like to see them breaking later with a reaxff or MLIP such as MatGL.
  • How do I show the cell and bonds? should I allow some flags to represent bonds? Or am I doing a totally wrong cell?
  • Do automatic tools such as MDTraj or MDAnalysis have an interface to ASE?
  • I know I can use VMD, but my local file is aliased at /Applications/VMD\ 1.9.4a57-x86_64-Rev12.app/Contents/Resources/VMD.app/Contents/MacOS/VMD
  • I tried with the conda install of AVOGADRO but I get:
read_traj = ase.io.trajectory.TrajectoryReader(traj_file)
view(read_traj, viewer='Avogadro')
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[15], line 2
      1 read_traj = ase.io.trajectory.TrajectoryReader(traj_file)
----> 2 view(read_traj, viewer='Avogadro')

File ~/miniconda3/lib/python3.9/site-packages/ase/visualize/__init__.py:10, in view(atoms, data, viewer, repeat, block)
      7     return
      9 vwr = viewers[viewer.lower()]
---> 10 handle = vwr.view(atoms, data=data, repeat=repeat)
     12 if block and hasattr(handle, 'wait'):
     13     status = handle.wait()

File ~/miniconda3/lib/python3.9/site-packages/ase/visualize/external.py:72, in CLIViewer.view(self, atoms, data, repeat)
     66     atoms = atoms.repeat(repeat)
     68 proc = subprocess.Popen(
     69     [sys.executable, '-m', 'ase.visualize.external'],
     70     stdin=subprocess.PIPE)
---> 72 pickle.dump((self, atoms, data), proc.stdin)
     73 proc.stdin.close()
     74 return proc

TypeError: cannot pickle '_io.BufferedReader' object

/Users/marcodigennaro/miniconda3/lib/python3.9/runpy.py:127: RuntimeWarning: 'ase.visualize.external' found in sys.modules after import of package 'ase.visualize', but prior to execution of 'ase.visualize.external'; this may result in unpredictable behaviour
  warn(RuntimeWarning(msg))

Can anyone advise on any of the previous points?

Thank you

Marco

$\endgroup$
2
  • $\begingroup$ Bond visualization is tricky. This is because each program has its own way to do it. Did you try with other software like VMD, Jmol? $\endgroup$
    – Camps
    Jul 13, 2023 at 12:15
  • $\begingroup$ I tried with the conda installed vmd and avogadro. No chance. Is there a way to use my local installation of VMD with the proper location? $\endgroup$ Jul 14, 2023 at 11:08

1 Answer 1

2
$\begingroup$
  • To visualize a trajectory in ASE, you have to use the default 'ase' viewer. The 'x3d' viewer currently only allows visualizing one structure.

  • When you open the ase viewer GUI, you can simply press Ctrl+B to visualize bonds, and Ctrl+U to visualize unit cell. In command line, you can simply do ase gui -b md.traj to visualize bonds.

  • If you want to make a movie that shows the change of the bonds, it becomes tricky. Although you can visualize bonds in ase GUI, when you save a snapshot as an image, the bonds disappear. Writing to a movie, e.g. ase.io.write('movie.gif', read_traj), do not support showing bonds either. Maybe you can work around by taking a screenshot for each snapshot, but my suggestion would be to download the POV-Ray tool. You can find a code example here for generating a high quality image of the C$_2$H$_4$ molecule with bonds using ASE and POV-Ray. You will need to generate an image for each snapshot, then combine them into a movie.

  • To the best of my knowledge, neither MDTraj nor MDAnalysis have an interface to ASE. However, you can check out the list of structure file formats supported by ASE here. Essentially, if you choose a format that can be read and written by both ASE and MDTraj/MDAnalysis, you are good to go.

$\endgroup$
7
  • $\begingroup$ Thank you for the extensive answer. Unfortunately, 'ase' or 'x3d' give exactly the same result, also from the command line. There is a warning message "setting an array element with a sequence. The requested array would exceed the maximum number of dimension of 1." $\endgroup$ Jul 24, 2023 at 13:32
  • $\begingroup$ @MarcoDiGennaro What do you mean "'ase' and 'x3d' give exactly the same result"? They are completely different viewers. Unless you provide your trajectory file, I cannot know why it isn't working for you. I have tested some trajectory files and it works as I stated. $\endgroup$
    – Shaun Han
    Jul 24, 2023 at 16:33
  • $\begingroup$ I mean they both open a python 3.11 window (3 actually: graph, movie and trajectory) $\endgroup$ Jul 24, 2023 at 17:49
  • $\begingroup$ <Popen: returncode: None args: ['/Users/marcodigennaro/miniconda3/envs/PGEL/...> $\endgroup$ Jul 24, 2023 at 17:52
  • $\begingroup$ @MarcoDiGennaro Yes they are supposed to open those 3 windows. So what's the problem? $\endgroup$
    – Shaun Han
    Jul 25, 2023 at 8:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .