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

Calculate dihedral angles from xtc trajectory #1335

Closed
xiki-tempula opened this issue May 5, 2017 · 4 comments
Closed

Calculate dihedral angles from xtc trajectory #1335

xiki-tempula opened this issue May 5, 2017 · 4 comments
Labels

Comments

@xiki-tempula
Copy link
Contributor

xiki-tempula commented May 5, 2017

Expected behaviour

I'm interested in calculating the time dependent change of a particular dihedral angle from a xtc trajectory and I expect to get a list of angles. I copied the example from https://github.com/MDAnalysis/MDAnalysisCookbook/blob/master/examples/backbone_dihedral.py

Actual behaviour

File "./dihedral_analysis.py", line 66, in
collection.compute(u.trajectory)

File "./mdanalysis/package/MDAnalysis/core/Timeseries.py", line 139, in compute
self.data = trj.correl(self, start, stop, step)

AttributeError: 'XTCReader' object has no attribute 'correl'

Code to reproduce the behaviour

from MDAnalysis import Universe, collection, Timeseries
collection.clear()
u = Universe(gro, xtc)
selection = 'resname {} and resid {} and name {}'
ALA2N = selection.format('ALA', 2, 'N')
ALA2CA = selection.format('ALA', 2, 'CA')
ALA2C = selection.format('ALA', 2, 'C')
TYR3N = selection.format('TYR', 3, 'N')
psi = [ALA2N, ALA2CA, ALA2C, TYR3N]
psi_angle = [u.select_atoms(atom) for atom in psi]
collection.addTimeseries(Timeseries.Dihedral(psi_angle))
collection.compute(u.trajectory)

I'm not quite sure why you need to call this correl function? I guess to calculate the dihedral angle, you only need four cartesian coordinates?
Something like

psi_list = []
for ts in u.trajectory:
    atoms = [u.select_atoms(atom) for atom in psi]
    cords = [atom.positions[0] for atom in atoms]
    psi_list.append(dihedral(cords))

Currently version of MDAnalysis:

py35, 0.16.0

@richardjgowers
Copy link
Member

richardjgowers commented May 5, 2017

I've never really used timeseries myself, I think the following should work..

from MDAnalysis import Universe

u = Universe(gro, xtc)
selection = 'resname {} and resid {} and name {}'
ALA2N = selection.format('ALA', 2, 'N')
ALA2CA = selection.format('ALA', 2, 'CA')
ALA2C = selection.format('ALA', 2, 'C')
TYR3N = selection.format('TYR', 3, 'N')
psi = [ALA2N, ALA2CA, ALA2C, TYR3N]
psi_angle = sum([u.select_atoms(atom) for atom in psi])  # sum of Atoms creates an AtomGroup
psi_angle = psi_angle.dihedral  # convert AtomGroup to Dihedral object

psi_list = []
for ts in u.trajectory:
    psi_list.append(psi_angle.value())
  • EDIT (@orbeckst): removed any reference to Timeseries or correl because it is not needed for the solution. Just to make sure that anyone else who might find this solution later will not become confused.

@xiki-tempula
Copy link
Contributor Author

@richardjgowers Thank you. It solved my problem.

@kain88-de
Copy link
Member

The timeseries feature only works for dcd files or a trajectory copied into memory.

@orbeckst
Copy link
Member

orbeckst commented May 7, 2017

As @kain88-de says, correl is not generally implemented. For DCD it contains code at the C-level to do simple trajectory analysis. You basically describe all the analysis that you want to do in your correl collection (the whole thing was inspired by CHARMM's CORREL functionality). Then you compute all your observables in one sweep with correl.compute(). In principle this is a good way to stack analysis and amortize the high I/O cost per frame but it relies on the reader implementing the functionality, which is not very flexible.

Typically we recommend using AnalysisBase to write general analysis functions. At some point we might figure out how to "stack" multiple analysis classes and basically do the same thing that correl does, just in a general way, and at the Python level.

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

No branches or pull requests

4 participants