Re: [AMBER] mmP(G)BSA correlation time

From: <psu4.uic.edu>
Date: Fri, 30 Aug 2013 10:30:58 -0500

Hello all,

   Thanks Jan-Philip's solution. It works! So it seems like our
trouble-shooting was in the wrong direction : /

   However, there is a new error message pops out:

Loading and checking parameter files for compatibility...
Loading and checking parameter files for compatibility...
Traceback (most recent call last):
  File "./python_API_2.py", line 21, in <module>
    total_mut = data.mutant['gb']['complex']['TOTAL'].copy()
*AttributeError: 'mmpbsa_data' object has no attribute 'mutant'*

###################### Here is the script ###############

#!/usr/bin/env python

import os

import sys

sys.path.append(os.path.join(os.getenv('AMBERHOME'), 'bin'))

from MMPBSA_mods import API as MMPBSA_API

import matplotlib.pyplot as plt

import numpy as np

data = MMPBSA_API.load_mmpbsa_info('_MMPBSA_info')

total = data['gb']['complex']['TOTAL'].copy()

data = MMPBSA_API.load_mmpbsa_info('_MMPBSA_info')

*total_mut = data.mutant['gb']['complex']['TOTAL'].copy()*

total -= total.mean()

total /= total.std()

total2 = total.copy() / len(total)

acor = np.correlate(total, total2, 'full')

total_mut -= total_mut.mean()

total_mut /= total_mut.std()

total2_mut = total_mut.copy() / len(total_mut)

acor_mut = np.correlate(total_mut, total2_mut, 'full')

xdata = np.arrange(0, len(total))

plt.plot(xdata, acor[len(acor)//2:], xdata, acor_mut[len(acor)//2:])

plt.show()

################################################

  Could anyone kindly offer some suggestions? Thanks.

  Cheers,
  Henry



On Fri, Aug 30, 2013 at 2:56 AM, Jan-Philip Gehrcke <jgehrcke.googlemail.com
> wrote:

> Hello Henry,
>
> This is one of the funny problems when you are working with Python and
> forget to use a proper shebang*. I ran into this a couple of times already.
>
> When you execute the Python script as you did (via ./python_API.py) and
> it does not explicitly state with which interpreter it should be
> executed, the current shell spawns a sub shell and executes the script.
> The first statements in your Python script are import statements. When
> you type 'man import' you see that this is command known to your
> operating system. However, it does something one would not necessarily
> expect:
>
> "import - saves any visible window on an X server and outputs it as an
> image file. You can capture a single window, the entire screen, or any
> rectangular portion of the screen."
>
> So the two import statements (importing sys and os) at the beginning of
> your Python script were valid shell syntax and made your machine create
> the 'sys' and 'os' files, containing screenshots of your desktop. Fun.
> Of course, your shell does not understand Python syntax in general,
> which is why you later on get these syntax errors:
>
> > ./python_API.py: line 7: syntax error near unexpected token
> `os.path.join'
> > ./python_API.py: line 7:
> > `sys.path.append(os.path.join(os.getenv(’AMBERHOME’), ’bin’))'
>
> The solution is simple: put
>
> #!/usr/bin/env python
>
> at the top of your Python script. It should make your shell invoke the
> Python interpreter when executing this script.
>
>
> ** The shebang is the first line in a script file stating which
> interpreter should be used to interpret the script file. See
> http://en.wikipedia.org/wiki/Shebang_%28Unix%29 for background info.
>
>
> Cheers,
>
> Jan-Philip
>
>
>
> On 08/30/2013 05:19 AM, psu4.uic.edu wrote:
> > Hi Jason,
> >
> > Thanks for your prompt reply. So we try to use the python API
> script in
> > AmberTools 13 :
> >
> > #################################### Here is the python script, *
> > python_API.py, * ######################
> >
> > import os
> >
> > import sys
> >
> > sys.path.append(os.path.join(os.getenv('AMBERHOME'),'bin'))
> >
> > from MMPBSA_mods import API as MMPBSA_API
> >
> > import matplotlib.pyplot as plt
> >
> > import numpy as np
> >
> > data = MMPBSA_API.load_mmpbsa_info('_MMPBSA_info')
> >
> > total = data['gb']['complex']['TOTAL'].copy()
> >
> > data = MMPBSA_API.load_mmpbsa_info('_MMPBSA_info')
> >
> > total_mut = data.mutant['gb']['complex']['TOTAL'].copy()
> >
> > total -= total.mean()
> >
> > total /= total.std()
> >
> > total2 = total.copy() / len(total)
> >
> > acor = np.correlate(total, total2, 'full')
> >
> > total_mut -= total_mut.mean()
> >
> > total_mut /= total_mut.std()
> >
> > total2_mut = total_mut.copy() / len(total_mut)
> >
> > acor_mut = np.correlate(total_mut, total2_mut, 'full')
> >
> > xdata = np.arrange(0, len(total))
> >
> > plt.plot(xdata, acor[len(acor)//2:], xdata, acor_mut[len(acor)//2:])
> >
> > plt.show()
> >
> > #################################################################3
> >
> > We have set up $AMBERHOME correctly and installed *python*,
> > *numpy*<http://www.numpy.org/>,
> > and *matplotlib* <http://matplotlib.org/index.html>
> >
> > login2$ python
> >
> > Python 2.7.2 |EPD 7.2-2 (64-bit)| (default, Jul 3 2011, 15:17:51)
> >
> > [GCC 4.1.2 20080704 (Red Hat 4.1.2-44)] on linux2
> >
> > Type "packages", "demo" or "enthought" for more information.
> >
> > >>> import numpy
> >
> >>>> print numpy.__version__
> >
> > 1.6.1
> >
> >>>> import matplotlib
> >
> >>>> print matplotlib.__version__
> >
> > 1.1.0
> >
> >
> > Then we do *"./python_API.py" *in the directory where "_MMPBSA_info",
> > related _MMPBSA* and topology files are. After waiting for about an
> > hour, the following error messages will keep popping out:
> >
> > ./python_API.py: line 7: syntax error near unexpected token
> `os.path.join'
> > ./python_API.py: line 7:
> > `sys.path.append(os.path.join(os.getenv(’AMBERHOME’), ’bin’))'
> >
> > However, the script does generate two files: os and sys*.
> *Interestingly,
> > if we open the "sys" file in the image software, it shows our Linux
> > terminal (as attached). * *We do have X11 forwarding set up correctly
> by
> > "ssh -X" and other images can be generated correctly in xmgrace remotely.
> >
> > Could you kindly offer some comments? Thanks.
> >
> >
> > Cheers,
> >
> > Henry
> >
> >
> >
> >
> > On Wed, Aug 28, 2013 at 6:59 AM, Jason Swails <jason.swails.gmail.com
> >wrote:
> >
> >> On Tue, Aug 27, 2013 at 7:57 PM, <psu4.uic.edu> wrote:
> >>
> >>> Dear Amber,
> >>>
> >>> We have a question about calculating correlation time of mmP(G)BSA
> dG
> >>> values. After consulting the amberTools 13 manual, old mailing
> >>> list<http://archive.ambermd.org/200712/0070.html>and the manuscripts
> >>> using the statistical inefficiency method (J. Chem.
> >>> Phys. 120, 2618 (2004); doi: 10.1063/1.1638996 & J Comput Chem 31:
> >>> 837–846, 2010 ), we assume the following way is correct to calculate
> >>> correlation time of dG in mmP(G)BSA?
> >>>
> >>> 1. Run MD simulation and save the trajectory in every picosecond
> (ps).
> >>>
> >>> 2. Calculate mmP(G)BSA dGbind using every ps snapshot from the MD
> >>> trajectory. Save the .csv file during mmP(G)BSA (Activate -eo flag).
> >>>
> >>> 3. Write a script to calculate the dGbind correlation time using
> dGbind
> >>> of each snapshot from the .csv file by the statistical inefficiency
> >> method.
> >>>
> >>> * statistical inefficiency method: correlation time= (block
> length) *
> >>> (the variance of the block average of X) / (the variance of the
> >>> distribution (X))
> >>>
> >>
> >> This way will work, but there is an easier method if you plan to use
> Python
> >> to analyze your data (with, e.g., numpy, scipy, pandas, etc.). See
> pages
> >> 376--377 of the AmberTools 13 manual where it describes using the Python
> >> API giving an example where the autocorrelation function is printed.
> >>
> >> The binding energy can be computed pretty easily by just subtracting the
> >> receptor and ligand TOTALs from the complex TOTAL (numpy arrays follow
> >> standard vector add/subtract rules). This approach prevents you from
> >> having to write a separate script to parse the CSV file. The example in
> >> the manual demonstrates how you would calculate the normalized
> >> autocorrelation function (which can also be used to estimate the
> >> statistical inefficiency in which the function becomes zero within some
> >> range of tolerance) and plots the resulting autocorrelation function
> with
> >> matplotlib, but you can adapt it for your own purposes.
> >>
> >> HTH,
> >> Jason
> >>
> >> --
> >> Jason M. Swails
> >> BioMaPS,
> >> Rutgers University
> >> Postdoctoral Researcher
> >> _______________________________________________
> >> AMBER mailing list
> >> AMBER.ambermd.org
> >> http://lists.ambermd.org/mailman/listinfo/amber
> >>
> >>
> >>
> >> _______________________________________________
> >> AMBER mailing list
> >> AMBER.ambermd.org
> >> http://lists.ambermd.org/mailman/listinfo/amber
>
>
> _______________________________________________
> AMBER mailing list
> AMBER.ambermd.org
> http://lists.ambermd.org/mailman/listinfo/amber
>



-- 
Pin-Chih Su (Henry Su)
Ph.D. canditate
Center for Pharmaceutical Biotechnology (MC 870)
College of Pharmacy, University of Illinois at Chicago
900 South Ashland Avenue, Room 1052
Chicago, IL 60607-7173
office      312-996-5388
fax         312-413-9303
_______________________________________________
AMBER mailing list
AMBER.ambermd.org
http://lists.ambermd.org/mailman/listinfo/amber
Received on Fri Aug 30 2013 - 09:00:02 PDT
Custom Search