import MDAnalysis as mda
mda.__version__

"""
Explanation: Loading MDAnalysis
End of explanation
"""


TOPOLOGY = 'data/adk.psf'

u = mda.Universe(TOPOLOGY)

"""
Explanation: The Universe
The basic object to load structures and trajectories into MDAnalysis are Universes. Universe take a topology and a trajectory (optional) as arguments
End of explanation
"""


u.atoms.n_atoms

"""
Explanation: Universe extract all the information in the topology and make them available to you. For example you can see how many atoms are in the topology
End of explanation
"""


u.residues.n_residues

"""
Explanation: Or the number of individual residues
End of explanation
"""


np.unique(u.residues.resnames)

"""
Explanation: We can also leverage numpy to see how many unique residue types there are. Residue names are stored in resnames.
End of explanation
"""


bb = u.atoms.select_atoms('backbone')

"""
Explanation: Select parts of a Topology
mostly we don't want to work on a complete topology but only analyze a specific part (selection) of it. For this we can create selections. If we want to select all backbone atoms for example
End of explanation
"""


print('number of backbone atoms : {}'.format(bb.n_atoms))
print('unique atoms types : {}'.format(np.unique(bb.names)))

"""
Explanation: To check that only backbone atoms are selected we can look if we only have C, CA, N and O atoms
End of explanation
"""


ca = u.atoms.select_atoms('protein and name CA')

print('number of Ca atoms : {}'.format(ca.n_atoms))
print('unique atoms types : {}'.format(np.unique(ca.names)))

"""
Explanation: Or we want to only select the C$_{\alpha}$-atoms.
End of explanation
"""


TRAJECTORY = 'data/adk_dims.dcd'

u = mda.Universe(TOPOLOGY, TRAJECTORY)

"""
Explanation: The complete syntax and possible selection can be look up here
 NOTE 
It is very important to select C$_{\alpha}$-atoms with the string protein and name CA because Calcium ions also have the name CA.
Load a trajectory
To load a simulation we can give the Universe object also a trajectory file as an argument
End of explanation
"""


u.trajectory.n_frames

"""
Explanation: now we can look how many frames the trajectory has
End of explanation
"""


for time_step in u.trajectory:
    print(time_step.time)

"""
Explanation: Iterating over a trajectory work pythonically.
End of explanation
"""


