Eigenstate / vmd-python

Installable VMD as a python module
Other
129 stars 24 forks source link

number of frames is 0 #43

Open sjzhao opened 1 year ago

sjzhao commented 1 year ago

Hi Robin,

I start Vmd and type gopython and then load a file by: molid = molecule.load('parm7', '1BIQ_solvate.top', 'crdbox', 'prod_imaged.mdcrd') tf = molecule.numframes(molid) print(tf) This will give the number of total frames of 300, it works.

However, when I put the same code in a python file like: from vmd import * mid = molecule.load('parm7', '1BIQ_solvate.top', 'crdbox', 'prod_imaged.mdcrd') tf = molecule.numframes(mid) print('Loaded mid is: ', mid) print('Total number frames is', tf)

The total number of frames is 0.

Do you have any idea of what is wrong here? Thanks.

jvermaas commented 1 year ago

Have you looked at the docs? What you are doing in VMD depends on behavior described in the user guide, where molecule.load in VMD 1.9.3 (or I think 1.9.4) will basically wait until all frames are loaded before returning. I think in the rejiggering to get this to work for python3, this side effect disappeared.

sjzhao commented 1 year ago

I just want to load the topo and mdcrd file, then get the total number of frames, and do a for loop base on the frames. I add a sleep(20) after the load function, but it does not work at all.

sjzhao commented 1 year ago

This is the example from the docs: from vmd import molecule

molid = molecule.load("parm7", "system.prmtop") molecule.read(molid, "netcdf", "simulation.nc", skip=5, waitfor=-1) last_frame = molecule.numframes - 1 molecule.write(molid, "pdb", "last_frame.pdb", first=last_frame)

However, molecule.numframes is a function which require molecule id. I did molecule.numframes(molid), which return 0