Closed AminKoochaki closed 7 years ago
The analysis module of MDAnalysis isn't imported by default. It contains optional dependencies for some specific analysis methods and we would like for people to be able to use MDAnalysis with minimal dependencies as well. Try to run the following code.
import MDAnalysis as mda
from MDAnalysis.analysis import polymer
u = mda.Universe('325element.xyz')
pmeecl = u.select_atoms('name C1 C2 H1 O1 O2')
PL = polymer.PersistenceLength(pmeecl).run()
Thanks for your kind reply.
I ran this code but I encountered with this error:
line 82, in __init__
lens = [len(ag) for ag in atomgroups]
TypeError: object of type 'Atom' has no len()
Judging from the docs for MDAnalysis.analysis.polymer.PersistenceLength you are not providing the correct list of atomgroups in the variable pmeeecl
:
atomgroups (list) – List of atomgroups. Each atomgroup should represent a single polymer chain, ordered in the correct order.
@kain88-de 's example is incorrect, I think, because
pmeecl = u.select_atoms('name C1 C2 H1 O1 O2')
will give you a single atomgroup and that is interpreted as a list of Atoms, hence your error.
Btw,
pmeeecl = u.atoms.select_atoms('name C1', 'name C2', 'name H1', 'name O1', 'name O2')
is probably also not what you want: it will also give you a single AtomGroup.
What is a single polymer in your simulation? If it is a single residue you could do
pmeecl = [polymer.atoms for polymer in u.select_atoms("name C1 C2 H1 O1 O2").residues]
(assuming that "name C1 C2 H1 O1 O2"
selects all your atoms in your polymers).
If you provide a bit more information on your system then we (especially @richardjgowers ) might be able to give more help.
edit: You might also be able to use AtomGroup.groupby()
to get your polymers if there are other topology attributes that you can use to distinguish them.
If you don't have any simple marker for the polymer molecules (such as resid or segment id) then you can also slice your atom group. Eg if you know that each polymer contains n_monomer
atoms:
n_monomer = 5
polymers = u.select_atoms("name C1 C2 H1 O1 O2")
pmeecl = [ polymers[i:i+n_monomer] for i in range(0, polymers.n_atoms, n_monomer) ]
@AminKoochaki So you (probably?) won't want a hydrogen in the persistence length calculation as you're looking at the curvature of the polymer backbone.
If you've only got one polymer chain in the system, you should provide a list containing just one AtomGroup, so PL = MDAnalysis.analysis.polymer.PersistenceLength([pmeeecl])
I have a single polymer chain with several water molecules and I want to calculate the persistence length of that after simulation by LAMMPS and by xyz output file. As I understand from papers, the persistence length would be the correlation between the first segment in the chain and the rest of the chain.
I can have pdb, psf, xyz as well as dcd file from my analysis.
Based on your comments I ran the following code by MDAnalysis module.
import MDAnalysis as mda
from MDAnalysis.analysis import polymer
u = mda.Universe('325element.xyz')
pmeeecl = u.select_atoms('name C1 C2 H1 O1 O2')
water = u.select_atoms('name H2 O3')
print(u.atoms)
print(pmeeecl.atoms)
print(water.atoms)
PL = polymer.PersistenceLength([pmeeecl])
print(PL)
The group of my polymer chain (pmeeecl) and the water have been created successfully based on the above code.
In addition, according to the richardjgowers comment there is no error at the end of the analysis. But, I take <MDAnalysis.analysis.polymer.PersistenceLength object at 0x7f14fa398f90> result and I don’t know exactly what it means.
The typical analysis workflow includes
(This is not well documented at the moment at should probably be somewhere in http://www.mdanalysis.org/docs/documentation_pages/analysis_modules.html)
In your case, try
pmeeecl = u.select_atoms('name C1 C2 H1 O1 O2')
PL = polymer.PersistenceLength([pmeeecl])
PL.run()
PL.perform_fit()
PL.plot()
The docs for this analysis are not exhaustive and you should definitely look at the source code http://www.mdanalysis.org/docs/_modules/MDAnalysis/analysis/polymer.html#PersistenceLength to better understand what is happening (I would avoid using any code as a pure black box...). In particular from reading the code it seems that it assumes that all the selected atoms are along the polymer chain because it computes direction vectors between subsequent atoms (i.e., between subsequent segments of the chain). Thus, it assumes that you only list one atom per segment.
As I understand from papers, the persistence length would be the correlation between the first segment in the chain and the rest of the chain.
This code computes correlations between all segments. ... — @richardjgowers please feel free to correct me.
@orbeckst I ran the code based on your comment. The following error was generated. I searched other repositories and I found out that I must upgrade the numpy. But, after update that, this error has not corrected yet.
Intel MKL FATAL ERROR: Cannot load libmkl_avx.so or libmkl_def.so /home/amin/anaconda2/lib/python2.7/site-packages/MDAnalysis/analysis/polymer.py:172: RuntimeWarning: overflow encountered in exp return np.exp(-x/a)
It looks as if you're using conda. Did you update your conda installation and did you install MDAnalysis through conda?
You should not have any library loading errors when installing through conda. Fix that problem first.
It is possible that the overflow warning indicates that your data are not looking like an exp – look at your raw data. @richardjgowers can say more, I don't really know the persistence code very well.
@AminKoochaki did you manage to solve your conda problem?
If not, can you paste the output from
conda list
in the environment where you run MDAnalysis?
There's a possibility that you get incompatible numpy packages if you use different channels.
@orbeckst I apologize for delayed response. I updated my conda as well as anaconda. Also, I reinstalled MDAnalysis through coda. Therefore, my conda list is:
# packages in environment at /home/amin/anaconda2:
#
_license 1.1 py27_1
alabaster 0.7.10 py27_0 conda-forge
anaconda 4.4.0 np112py27_0
anaconda-client 1.6.3 py27_0 conda-forge
anaconda-navigator 1.6.2 py27_0
anaconda-project 0.6.0 py27_0
argcomplete 1.0.0 py27_1
asn1crypto 0.22.0 py27_0 conda-forge
astroid 1.4.9 py27_0
astropy 1.3.2 np112py27_0 conda-forge
babel 2.4.0 py27_0
backports 1.0 py27_0
backports.shutil_get_terminal_size 1.0.0 py27_1 conda-forge
backports_abc 0.5 py27_0
beautifulsoup4 4.6.0 py27_0
biopython 1.68 np112py27_0
biopython 1.69 <pip>
bitarray 0.8.1 py27_0
blaze 0.10.1 py27_0
bleach 1.5.0 py27_0 conda-forge
bokeh 0.12.5 py27_1
boto 2.46.1 py27_0
boto3 1.4.4 py27_0 conda-forge
botocore 1.5.55 py27_0 conda-forge
bottleneck 1.2.1 np112py27_0
ca-certificates 2017.4.17 0 conda-forge
cairo 1.14.8 0
cdecimal 2.3 py27_2
certifi 2017.4.17 py27_0 conda-forge
cffi 1.10.0 py27_0 conda-forge
chardet 3.0.3 py27_0
chest 0.2.3 py27_0
click 6.7 py27_0
cloudpickle 0.2.2 py27_0
clyent 1.2.2 py27_0
colorama 0.3.9 py27_0 conda-forge
conda 4.3.22 py27_0 conda-forge
conda-env 2.6.0 0 conda-forge
configobj 5.0.6 py27_0
configparser 3.5.0 py27_0
contextlib2 0.5.5 py27_0 conda-forge
cryptography 1.8.1 py27_0
curl 7.52.1 0
cycler 0.10.0 py27_0
cython 0.25.2 py27_0
cytoolz 0.8.2 py27_0
dask 0.14.3 py27_1
datashape 0.5.4 py27_0
dbus 1.10.10 0
decorator 4.0.11 py27_0
dill 0.2.5 py27_0
distributed 1.16.3 py27_0 conda-forge
docutils 0.13.1 py27_0
entrypoints 0.2.2 py27_1 conda-forge
enum34 1.1.6 py27_0
et_xmlfile 1.0.1 py27_0
expat 2.1.0 0
fastcache 1.0.2 py27_1
flask 0.12.2 py27_0
flask-cors 3.0.2 py27_0
fontconfig 2.12.1 3
freetype 2.5.5 2
funcsigs 1.0.2 py27_0
functools32 3.2.3.2 py27_0
futures 3.1.1 py27_0
get_terminal_size 1.0.0 py27_0
gevent 1.2.1 py27_0
giphy-ipython-magic 0.0.2 <pip>
glib 2.50.2 1
gmp 6.1.2 0 conda-forge
greenlet 0.4.12 py27_0 conda-forge
GridDataFormats 0.3.3 <pip>
griddataformats 0.3.3 py27_0 conda-forge
grin 1.2.1 py27_3
gst-plugins-base 1.8.0 0
gstreamer 1.8.0 0
h5py 2.7.0 np112py27_0 conda-forge
harfbuzz 0.9.39 2
hdf4 4.2.12 0 conda-forge
hdf5 1.8.17 1
heapdict 1.0.0 py27_1
html5lib 0.999 py27_0 conda-forge
icu 54.1 0
idna 2.5 py27_0 conda-forge
imageio 2.2.0 py27_0 conda-forge
imagesize 0.7.1 py27_0
ipaddress 1.0.18 py27_0
ipykernel 4.6.1 py27_0 conda-forge
ipython 5.3.0 py27_0 conda-forge
ipython_genutils 0.2.0 py27_0 conda-forge
ipywidgets 6.0.0 py27_0 conda-forge
isort 4.2.5 py27_0
itsdangerous 0.24 py27_0
jbig 2.1 0
jdcal 1.3 py27_0
jedi 0.10.2 py27_2
jinja2 2.9.6 py27_0
jmespath 0.9.3 py27_0 conda-forge
joblib 0.11 <pip>
joblib 0.11 py27_0 conda-forge
jpeg 9b 0
jsonschema 2.6.0 py27_0
jupyter 1.0.0 py27_3
jupyter_client 5.0.1 py27_0 conda-forge
jupyter_console 5.1.0 py27_0 conda-forge
jupyter_core 4.3.0 py27_0 conda-forge
lazy-object-proxy 1.2.2 py27_0
libffi 3.2.1 1
libgcc 4.8.5 2
libgfortran 3.0.0 1
libiconv 1.14 0
libnetcdf 4.4.1.1 4 conda-forge
libpng 1.6.27 0
libsodium 1.0.10 0
libtiff 4.0.6 3
libtool 2.4.2 0
libxcb 1.12 1
libxml2 2.9.4 0
libxslt 1.1.29 0
llvmlite 0.18.0 py27_0
locket 0.2.0 py27_1
lxml 3.7.3 py27_0 conda-forge
markupsafe 0.23 py27_2
matplotlib 2.0.2 np112py27_0
mdanalysis 0.16.2 np112_0 conda-forge
mdanalysistests 0.16.2 py27_0 conda-forge
MDAnalysisTests 0.16.0 <pip>
mdtraj 1.8.0 np112py27_1 conda-forge
mistune 0.7.4 py27_0 conda-forge
mkl 2017.0.1 0
mkl-service 1.1.2 py27_3
mmtf-python 1.0.5 <pip>
mmtf-python 1.0.5 py27_0 conda-forge
mock 2.0.0 py27_0 conda-forge
mock 2.0.0 <pip>
moltemplate 2.1.2 <pip>
mpmath 0.19 py27_1
msgpack-python 0.4.8 py27_0 conda-forge
msgpack-python 0.4.8 <pip>
multipledispatch 0.4.9 py27_0
navigator-updater 0.1.0 py27_0
nbconvert 5.1.1 py27_0 conda-forge
nbformat 4.3.0 py27_0 conda-forge
netcdf4 1.2.8 np112py27_0 conda-forge
networkx 1.11 py27_0
nltk 3.2.3 py27_0
nose 1.3.7 py27_1
notebook 5.0.0 py27_0 conda-forge
numba 0.33.0 np112py27_0
numexpr 2.6.2 np112py27_0 conda-forge
numpy 1.12.1 py27_0
numpy 1.12.1 <pip>
numpydoc 0.6.0 py27_0
odo 0.5.0 py27_1
olefile 0.44 py27_0 conda-forge
openpyxl 2.4.7 py27_0
openssl 1.0.2l 0 conda-forge
packaging 16.8 py27_0 conda-forge
pandas 0.20.1 np112py27_0 conda-forge
pandoc 1.19.2 0 conda-forge
pandocfilters 1.4.1 py27_0 conda-forge
pango 1.40.3 1
partd 0.3.8 py27_0 conda-forge
path.py 10.3.1 py27_0
pathlib2 2.2.1 py27_0 conda-forge
patsy 0.4.1 py27_0
pbr 3.0.1 <pip>
pbr 3.1.1 py27_0 conda-forge
pcre 8.39 1
pep8 1.7.0 py27_0
pexpect 4.2.1 py27_0
pickleshare 0.7.4 py27_0
pillow 4.1.1 py27_0
pip 9.0.1 py27_1
pixman 0.34.0 0
ply 3.10 py27_0 conda-forge
prompt_toolkit 1.0.14 py27_0 conda-forge
psutil 5.2.2 <pip>
psutil 5.2.2 py27_0
ptyprocess 0.5.1 py27_0
py 1.4.33 py27_0 conda-forge
pyasn1 0.1.9 py27_0
pycairo 1.10.0 py27_0
pycosat 0.6.2 py27_0
pycparser 2.17 py27_0
pycrypto 2.6.1 py27_6
pycurl 7.43.0 py27_2
pyflakes 1.5.0 py27_0
pygments 2.2.0 py27_0 conda-forge
pylint 1.6.4 py27_1
pyodbc 4.0.16 py27_0
pyopenssl 17.0.0 py27_0
pyparsing 2.1.4 py27_0
pyqt 5.6.0 py27_2
pytables 3.3.0 np112py27_0 conda-forge
pytest 3.0.7 py27_0 conda-forge
python 2.7.13 0
python-dateutil 2.6.0 py27_0
pytz 2017.2 py27_0 conda-forge
pywavelets 0.5.2 np112py27_0 conda-forge
pyyaml 3.12 py27_0
pyzmq 16.0.2 py27_0
qt 5.6.2 4
qtawesome 0.4.4 py27_0 conda-forge
qtconsole 4.3.0 py27_0 conda-forge
qtpy 1.2.1 py27_0
readline 6.2 2
redis 3.2.0 0
redis-py 2.10.5 py27_0
requests 2.14.2 py27_0
rope 0.9.4 py27_1
ruamel_yaml 0.11.14 py27_1
s3fs 0.1.1 py27_0 conda-forge
s3transfer 0.1.10 py27_1 conda-forge
scandir 1.5 py27_0
scikit-image 0.13.0 np112py27_0 conda-forge
scikit-learn 0.18.1 np112py27_1
scipy 0.19.0 np112py27_0
seaborn 0.7.1 py27_0
setuptools 27.2.0 py27_0
simplegeneric 0.8.1 py27_1
singledispatch 3.4.0.3 py27_0
sip 4.18 py27_0
six 1.10.0 py27_0
snowballstemmer 1.2.1 py27_0
sockjs-tornado 1.0.3 py27_0
sortedcollections 0.5.3 py27_0
sortedcontainers 1.5.7 py27_0
sphinx 1.5.6 py27_0 conda-forge
spyder 3.1.4 py27_0 conda-forge
sqlalchemy 1.1.9 py27_0
sqlite 3.13.0 0
ssl_match_hostname 3.4.0.2 py27_1
statsmodels 0.8.0 np112py27_0 conda-forge
subprocess32 3.2.7 py27_0
sympy 1.0 py27_0
tblib 1.3.2 py27_0 conda-forge
terminado 0.6 py27_0
testpath 0.3 py27_0 conda-forge
tk 8.5.18 0
toolz 0.8.2 py27_0
tornado 4.5.1 py27_0 conda-forge
traitlets 4.3.2 py27_0 conda-forge
unicodecsv 0.14.1 py27_0
unixodbc 2.3.4 0 conda-forge
wcwidth 0.1.7 py27_0
webencodings 0.5 py27_0 conda-forge
werkzeug 0.12.2 py27_0 conda-forge
wheel 0.29.0 py27_0
widgetsnbextension 2.0.0 py27_0 conda-forge
wrapt 1.10.10 py27_0
xlrd 1.0.0 py27_0
xlsxwriter 0.9.6 py27_0
xlwt 1.2.0 py27_0
xz 5.2.2 1
yaml 0.1.6 0
zeromq 4.1.5 0
zict 0.1.2 py27_0 conda-forge
zlib 1.2.8 3
I ran MDAnalysis in Ubuntu 16.04.
When I ran after these updates, I encounter with this:
/home/amin/anaconda2/lib/python2.7/site-packages/MDAnalysis/analysis/polymer.py:172: RuntimeWarning: overflow encountered in exp
return np.exp(-x/a)
/home/amin/anaconda2/lib/python2.7/site-packages/scipy/optimize/minpack.py:779: OptimizeWarning: Covariance of the parameters could not be estimated
category=OptimizeWarning)
Process finished with exit code 0
It looks as if you successfully installed everything.
I hope that @richardjgowers can chime in for the overflow warning. From what I gather, the fit to exp fails. I would
.results
) to see if it can be meaningfully fit by an exponential decay (the assumption in the persistence length calculation).There has not been any more activity on this question so I am closing it. Feel free to add more comments if necessary.
Hi, @orbeckst I am new to MDanalysis and python, I tried running the same code:
import MDAnalysis as mda from MDAnalysis.analysis import polymer
u = mda.Universe('config.gro')
pmeeecl = u.select_atoms('name N CA C O') PL = polymer.PersistenceLength([pmeeecl]) PL.run() PL.perform_fit() PL.plot()
print(u.atoms) print(pmeeecl.atoms)
PL = polymer.PersistenceLength([pmeeecl])
print(PL)
it gave me the following error. Please suggest the right way
File "persit.py", line 4, in <module> u = mda.Universe('config.gro') File "/home/saptarshi/.local/lib/python2.7/site-packages/MDAnalysis/core/universe.py", line 296, in __init__ "Error: {2}".format(self.filename, parser, err)) ValueError: Failed to construct topology from file config.gro with parser <class 'MDAnalysis.topology.GROParser.GROParser'>. Error: invalid literal for int() with base 10: ''
Hi,
This looks as if the GRO file is not properly read. How did you create the GRO file?
Can you read it with a Gromacs tool such as gmx editconf?
Oliver
-- Oliver Beckstein email: orbeckst@gmail.com
Am Oct 22, 2018 um 04:22 schrieb Karpurmanjari notifications@github.com:
Hi, @orbeckst I am new to MDanalysis and python, I tried running the same code:
import MDAnalysis as mda from MDAnalysis.analysis import polymer
u = mda.Universe('config.gro')
pmeeecl = u.select_atoms('name N CA C O') PL = polymer.PersistenceLength([pmeeecl]) PL.run() PL.perform_fit() PL.plot()
print(u.atoms) print(pmeeecl.atoms)
PL = polymer.PersistenceLength([pmeeecl])
print(PL)
it gave me the following error. Please suggest the right way
File "persit.py", line 4, in
u = mda.Universe('config.gro') File "/home/saptarshi/.local/lib/python2.7/site-packages/MDAnalysis/core/universe.py", line 296, in init "Error: {2}".format(self.filename, parser, err)) ValueError: Failed to construct topology from file config.gro with parser <class 'MDAnalysis.topology.GROParser.GROParser'>. Error: invalid literal for int() with base 10: '' — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
Hi,
Instead of asking on a closed issue, rather email the mailing list and put in a link to the old issue for any code that you are using.
If it's a bug the open a new issue, please.
Oliver
-- Oliver Beckstein email: orbeckst@gmail.com
Am Oct 22, 2018 um 04:22 schrieb Karpurmanjari notifications@github.com:
Hi, @orbeckst I am new to MDanalysis and python, I tried running the same code:
import MDAnalysis as mda from MDAnalysis.analysis import polymer
u = mda.Universe('config.gro')
pmeeecl = u.select_atoms('name N CA C O') PL = polymer.PersistenceLength([pmeeecl]) PL.run() PL.perform_fit() PL.plot()
print(u.atoms) print(pmeeecl.atoms)
PL = polymer.PersistenceLength([pmeeecl])
print(PL)
it gave me the following error. Please suggest the right way
File "persit.py", line 4, in
u = mda.Universe('config.gro') File "/home/saptarshi/.local/lib/python2.7/site-packages/MDAnalysis/core/universe.py", line 296, in init "Error: {2}".format(self.filename, parser, err)) ValueError: Failed to construct topology from file config.gro with parser <class 'MDAnalysis.topology.GROParser.GROParser'>. Error: invalid literal for int() with base 10: '' — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread.
Hi @orbeckst, I took the GRO file from gromacs generated data and modified it so as to only have the x y z Coordinates and the name of the corresponding atoms of the backbone of the polymer in the new gro file. Shall I directly use the Gro file as it is generated by gromacs?
I also tried using the unmodified TPR file along with it. It didn't work out as well.
On Mon 22 Oct, 2018, 10:48 PM Oliver Beckstein, notifications@github.com wrote:
Hi,
This looks as if the GRO file is not properly read. How did you create the GRO file?
Can you read it with a Gromacs tool such as gmx editconf?
Oliver
-- Oliver Beckstein email: orbeckst@gmail.com
Am Oct 22, 2018 um 04:22 schrieb Karpurmanjari <notifications@github.com :
Hi, @orbeckst I am new to MDanalysis and python, I tried running the same code:
import MDAnalysis as mda from MDAnalysis.analysis import polymer
u = mda.Universe('config.gro')
pmeeecl = u.select_atoms('name N CA C O') PL = polymer.PersistenceLength([pmeeecl]) PL.run() PL.perform_fit() PL.plot()
print(u.atoms) print(pmeeecl.atoms)
PL = polymer.PersistenceLength([pmeeecl])
print(PL)
it gave me the following error. Please suggest the right way
File "persit.py", line 4, in
u = mda.Universe('config.gro') File "/home/saptarshi/.local/lib/python2.7/site-packages/MDAnalysis/core/universe.py", line 296, in init "Error: {2}".format(self.filename, parser, err)) ValueError: Failed to construct topology from file config.gro with parser <class 'MDAnalysis.topology.GROParser.GROParser'>. Error: invalid literal for int() with base 10: '' — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or mute the thread. — You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/MDAnalysis/mdanalysis/issues/1428#issuecomment-431902984, or mute the thread https://github.com/notifications/unsubscribe-auth/AqTyQ5xi-ZOwRRmpWVhHansW-gOsvoPFks5unf4CgaJpZM4ODhLo .
Use the unmodified GRO file and then use MDAnalysis selections.
If the TPR file does not work, file an issue; I think all current version of the TPR format should work.
On Oct 22, 2018, at 10:34 AM, Karpurmanjari notifications@github.com wrote:
Hi @orbeckst, I took the GRO file from gromacs generated data and modified it so as to only have the x y z Coordinates and the name of the corresponding atoms of the backbone of the polymer in the new gro file. Shall I directly use the Gro file as it is generated by gromacs?
I also tried using the unmodified TPR file along with it. It didn't work out as well.
Hi @orbeckst I used unmodified gro file, which worked. But another issue has come up which I have opened with a new issue. https://github.com/Karpurmanjari/Issues/issues/1#issue-372824611
I am new to python and I want to calculate persistence length by MDAnalysis module. I am using bash Linux on Windows 10.
I have a polymer chain (pmeeecl) and water molecules in my system.
I appreciate if you help me to write appropriate code for serving this purpose.
Thanks.
Initial Code: