Selection of molecules in a layer

117 views
Skip to first unread message

sakiru Badmos

unread,
Jul 26, 2017, 8:46:39 PM7/26/17
to MDnalysis discussion

Hi everyone,

I was trying to select molecules within a particular layer (z<2.3 and z>2.6)and write the coordinates to a .pdb file using this code:

import MDAnalysis

from MDAnalysis.tests.datafiles import PDB, XTC

pdb_path= '/Users/macuser/desktop/Python/1ns_4sig.pdb'

xtc_path= '/Users/macuser/desktop/Python/1ns_4sig.xtc'

u = MDAnalysis.Universe(pdb_path, xtc_path)

group = u.select_atoms("resname SOL and resname HSS and prop z<2.3 and prop z> 2.6")

with MDAnalysis.Writer("SOL_HSS.xtc", protein.n_atoms) as W:

    for ts in u.trajectory:

        W.write(group)

I got this error " raise ImportError("Package MDAnalysisTests required!")"

                           "ImportError: Package MDAnalysisTests required!"

I am very new to MDAnalysis. Please help me.

Thanks.

Sakiru.

Tyler Reddy

unread,
Jul 26, 2017, 11:01:59 PM7/26/17
to mdnalysis-...@googlegroups.com
The tests & associated data files are installed separately. I think you could just do: pip install MDAnalysisTests



--
You received this message because you are subscribed to the Google Groups "MDnalysis discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mdnalysis-discussion+unsub...@googlegroups.com.
To post to this group, send email to mdnalysis-discussion@googlegroups.com.
Visit this group at https://groups.google.com/group/mdnalysis-discussion.
For more options, visit https://groups.google.com/d/optout.

Oliver Beckstein

unread,
Jul 26, 2017, 11:45:54 PM7/26/17
to MDnalysis discussion
Hi  Sakiru,

You do not need the line


    from MDAnalysis.tests.datafiles import PDB, XTC


in your script, just leave it out. It is used in the examples. If you want to do the examples (e.g., in the tutorial http://mdanalysis.org/MDAnalysisTutorial) the install the tests as Tyler said.

Oliver

sakiru Badmos

unread,
Jul 27, 2017, 4:37:50 AM7/27/17
to MDnalysis discussion
Thanks Tyler. I have removed that line but I got another error :

File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/MDAnalysis/c
oordinates/base.py", line 1851, in write
return self.write_next_timestep(ts)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/MDAnalysis/coordinates/XTC.py", line 98, in write_next_timestep
 self._xdr.write(xyz, box, step, time, precision)
File "MDAnalysis/lib/formats/libmdaxdr.pyx", line 734, in MDAnalysis.lib.formats.libmdaxdr.XTCFile.write (MDAnalysis/lib/formats/libmdaxdr.c:9518)
IndexError: Out of bounds on buffer access (axis 0)
Thanks

sakiru Badmos

unread,
Jul 27, 2017, 4:40:19 AM7/27/17
to MDnalysis discussion
Thanks Oliver. I have removed that line but I got another error :

File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/MDAnalysis/c
oordinates/base.py", line 1851, in write
return self.write_next_timestep(ts)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/MDAnalysis/coordinates/XTC.py", line 98, in write_next_timestep
 self._xdr.write(xyz, box, step, time, precision)
File "MDAnalysis/lib/formats/libmdaxdr.pyx", line 734, in MDAnalysis.lib.formats.libmdaxdr.XTCFile.write (MDAnalysis/lib/formats/libmdaxdr.c:9518)
IndexError: Out of bounds on buffer access (axis 0)
Thanks


Oliver Beckstein

unread,
Jul 27, 2017, 6:50:59 PM7/27/17
to mdnalysis-...@googlegroups.com
Can you try

import MDAnalysis
pdb_path= '/Users/macuser/desktop/Python/1ns_4sig.pdb'
xtc_path= '/Users/macuser/desktop/Python/1ns_4sig.xtc'

u = MDAnalysis.Universe(pdb_path, xtc_path)
group = u.select_atoms("resname SOL and resname HSS and prop z<2.3 and prop z> 2.6")
with MDAnalysis.Writer("SOL_HSS.xtc", group.n_atoms) as W:
for ts in u.trajectory:
W.write(group)


You need to give the size of your group, not of the protein.

Note that you are using a selection with distances. You will ONLY get the waters that are in this z range *at the beginning of your simulation*. It will NOT dynamically update. You can make it dynamically update but then your group will have varying number of waters and that does not work in XTC files.

Can you describe what you want to achieve? Then we might be able to give some hints.

Oliver
> --
> You received this message because you are subscribed to the Google Groups "MDnalysis discussion" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to mdnalysis-discus...@googlegroups.com.
> To post to this group, send email to mdnalysis-...@googlegroups.com.
--
Oliver Beckstein
orbe...@gmail.com * orbe...@gmx.net




sakiru Badmos

unread,
Jul 27, 2017, 8:39:26 PM7/27/17
to MDnalysis discussion
Thank you very much for your help Dr Oliver. I will start by describing my system. My system comprises a slab (silica, Alumina)  that is exposed to bulk area on both sides(i.e  no slab - slab - no slab) along x direction. Fluids such as water and methane occupy both the bulk area and inside the slab. I am interested in analysing only molecules found within the slab and I need to make appropriate selections. I will like to calculated radial distribution functions, density profiles, hydrogen bond dynamics etc for molecules only inside the slab. This is why I need the distance selection. How do I make these selections to calculate properties like RDF, MSD, density profile...
I also want to generate the cloud of water around solute inside the slab.

When I corrected the code as Dr Oliver suggested, I still had this error '  IndexError: Out of bounds on buffer access (axis 0)' I tried different selections and I discovered I could only make the selection when it was done separately for SOL and HSS ( I generated 2 pdb files containing each group). Then, I wanted to merge the two pdb files created. I tried the code below but I got only one frame ( the pdb files contain 1000 frames.
import MDAnalysis

u1=MDAnalysis.Universe("HSS.pdb")
u2=MDAnalysis.Universe("SOL.pdb")

u3=MDAnalysis.Merge(u1.select_atoms("resname HSS"), u2.atoms)
u3.atoms.write("system.pdb")
I will appreciate any help from you guys on how to select molecules in the slab and write the trajectory in a file (xtc or pdb)
Thank you very much
> To unsubscribe from this group and stop receiving emails from it, send an email to mdnalysis-discussion+unsub...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages