From: Rune Thomas Kidmose (
Date: Sun Jun 03 2018 - 14:33:45 CDT

Ahh yes this could be smart little trick I was looking for.

I knew that the latest loaded molecule becomes the top molecule, but I did not think of extracting whatever mol ID it is assigned, and use is as a variable to call later on.

I think this might do it, and of course it was relative easy. That being said if anyone else has other suggestions I will be glad to hear them.

Thx Ashar!


Fra: Ashar Malik <>
Sendt: 3. juni 2018 21:29
Til: Rune Thomas Kidmose
Emne: Re: vmd-l: problem with mol IDs when running script from same VMD session.

Every time a new molecule is loaded it becomes the "top" molecule.
You can use this.

if you load a molecule, you can fetch its ID using

molinfo top get id

you can save this number to a variable and use that in the remainder of your script.

Hope I understood your problem and this helps. Otherwise write back.

On Mon, Jun 4, 2018 at 7:02 AM, Rune Thomas Kidmose <<>> wrote:

Basically, I cant figure out how to reinitialize VMD before running the same script twice or more in the same session.

My current problem is that I have a script which loads 5 different molecules. During the loading each molecule is then automatic given a mol ID number (0-4) as is standard.

I then use those mol IDs to set various features for specfic molecules (view matrices, modstyles, modmaterials etc. so e.g. mol modcolor 0 3 ColorID 8 etc.). However, if I then make some changes within the tcl script and I want to reload the script to see the effects of the changes, I am hit with the problem that the molecules I now load get new mol ID's assigned (not 0-4 but e.g. 5-9). This means that the mol id specific commands are not executed on the newly loaded molecules. This is of course because I run the script in the same VMD 1.93 session that I just ran the script from. But even if manual delete the molecules before running the script again I still face the same problem.

My current solution is to just restart VDM and run the script, which works, but I cant help to wonder if there is some smart way to mitigate this?

I run the scripts using the play command from the tcl consol.

In PyMol I always start my scripts with the command "reinitialize" which resets everything in PyMol, does something related exist for VMD 1.93 ?

Does what I describe make sense?