Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with Plumed in Pyhton #712

Open
Gressy2113 opened this issue Jul 2, 2021 · 5 comments
Open

Problem with Plumed in Pyhton #712

Gressy2113 opened this issue Jul 2, 2021 · 5 comments

Comments

@Gressy2113
Copy link

Hello,
I have a problem with Python API.
The code given below takes results from metadynamics, do reweighting and create histogram. But the output file contains Nouns instead of histogram data.
When the same input data process in command line (binary code), histogram calculates in a correct way. So, this code should have a pointer to give array with right histogram and fes data (like h.dat and fes.dat).

`  # filecv - input file with meta dynamics results. 
    f = open('1.dat' , 'w') 
    with  plumed.Plumed(kernel=kernel) as p:  

          p.cmd("setMDEngine","driver")  
          p.cmd("setLogFile","test.log")
          p.cmd('setNatoms', 0)
          p.cmd("setTimestep", 1.)
          p.cmd("setKbT", 1.) 
          
          ib=plumed.InputBuilder(toplumed = p, tofile= f, kernel=kernel)
          p.cmd("init")
          ib.READ(LABEL='cv',  FILE=filecv,IGNORE_TIME=True, IGNORE_FORCES=True, VALUES='CV')
          ib.READ(LABEL='meta',FILE=filecv,IGNORE_TIME=True, IGNORE_FORCES=True, VALUES='M.rbias')
      
          p.cmd('update')
      
          print('ok')
          stop=np.array((1,),dtype='int')
          p.cmd("setStopFlag",stop)
          print(stop)
          stop[0]=0
          print(stop)
          i=0
          while(True):
              p.cmd('calc')
              i += 1
      
              if stop[0]!=0:
                  print(i,stop)
                  break
                  
          ib.REWEIGHT_METAD(LABEL='w1', TEMP=300, ARG='meta.rbias')
          ib.HISTOGRAM(LABEL='h1',ARG='cv', BANDWIDTH=0.005, GRID_BIN=50, GRID_MAX=0.4, GRID_MIN=-0.4, 
                       KERNEL='gaussian', LOGWEIGHTS='w1')
          ib.DUMPGRID(GRID='h1', FILE='/tmp/h.dat')
          p.cmd('update')
          ib.CONVERT_TO_FES(LABEL='ff', GRID='h1', MINTOZERO=True, TEMP=300)
          ib.DUMPGRID(GRID='ff', FILE='/tmp/fes.dat')
          p.cmd('update')
          p.cmd('runFinalJobs')
    f.close()

`

@GiovanniBussi
Copy link
Member

What do you mean with "the output file contains Nouns instead of histogram data"? Maybe "NaNs"?

If I understand correctly your input, you are first reading the whole trajectories and only then adding to the action list the analysis part. This is not expected to work: data should be analyzed while they are read. When you use plumed driver, the whole input is read first. So, I would suggest to try moving all the ib.SOMETHING up, before you scan the trajectory.

It is possible that things will work also if you leave CONVERT_TO_FES and DUMPGRID at the end though (i.e., you only move up REWEIGHT_METAD and HISTOGRAM) , unless PLUMED is so smart to know, while you are scanning the trajectory, that the HISTOGRAM will not be used and so does not compute it.

Giovanni

@Gressy2113
Copy link
Author

Yes, excuse me, I meant "NaNs"

I moved strings up, but nothing changed. I also tried to move up only REWEIGHT_METAD and HISTOGRAM, and it didn't help too (and moving ENDPLUMED up and down is also useless).

`

f = open('1.dat' , 'w') 

with  plumed.Plumed(kernel=kernel) as p:

    p.cmd("setMDEngine","driver")    
    p.cmd("setLogFile","test.log")
    p.cmd('setNatoms', 0)
    p.cmd("setTimestep", 1.)
    p.cmd("setKbT", 1.)
    ib=plumed.InputBuilder(toplumed = p, tofile= f, kernel=kernel)
    p.cmd("init")

    ib.READ(LABEL='cv',  FILE=filecv,IGNORE_TIME=True, IGNORE_FORCES=True, VALUES='CV')
    ib.READ(LABEL='meta',FILE=filecv,IGNORE_TIME=True, IGNORE_FORCES=True, VALUES='M.rbias')
    ib.READ(LABEL='uwa', FILE=filecv,IGNORE_TIME=True, IGNORE_FORCES=True, VALUES='UW.bias')
    ib.READ(LABEL='lwa', FILE=filecv,IGNORE_TIME=True, IGNORE_FORCES=True, VALUES='LW.bias')    
    
    ib.REWEIGHT_METAD(LABEL='w1', TEMP=300, ARG='meta.rbias')
    
    ib.HISTOGRAM(LABEL='h1',ARG='cv', BANDWIDTH=0.005, GRID_BIN=50, GRID_MAX=0.4, GRID_MIN=-0.4, 
                 KERNEL='gaussian', LOGWEIGHTS='w1')
    
    ib.DUMPGRID(GRID='h1', FILE='/tmp/h.dat')
    p.cmd('update')
    ib.CONVERT_TO_FES(LABEL='ff', GRID='h1', MINTOZERO=True, TEMP=300)
    ib.DUMPGRID(GRID='ff', FILE='/tmp/fes.dat')
    
    stop=np.array((1,),dtype='int')
         
    p.cmd("setStopFlag", stop)
  
    stop[0]=0
    i=0
    while(True):
        p.cmd('calc')
        i += 1
​
        if stop[0]!=0:
            print(i,stop)
            break
        
    ib.ENDPLUMED()
    p.cmd('update')
    p.cmd('runFinalJobs')
    
f.close()`

@GiovanniBussi
Copy link
Member

Do you see your commands are correctly processed when you check the test.log file?

@GiovanniBussi
Copy link
Member

Also I would say the two lines with p.cmd('update') are not needed (calc implies that statistics are updated as well)

@Gressy2113
Copy link
Author

There is test.log file. At the end it is 1 cycle, but file 'CV.00' has 60002 strings (1st is title), so it should be ~60000 cycles

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants