pythonbioinformaticsprotein-databasemoleculemdanalysis

Time series data for water molecules from its dcd file


I am trying to make a file which contain time series data of water molecules from dcd file. Is it possible to generate this data using any of MDAnalysis module or function? Or is there any python script to generate this file?

I need to generate this file containing two columns (one with z coordinates of water molecules and 2nd with respective timesteps) by using DCD file as input.


Solution

  • You can get the (z, t) time series in a variety of ways but I am showing the most basic one here. I assume that you also have a PSF topology file in addition to your DCD trajectory file (but really, any topology and trajectory file format will work in MDAnalysis). I also assume that the water oxygen atoms are named "OW".

    I am actually not clear how you want your "z, t" data structure to look like. If you have N water molecules, then you will have N z-coordinates per time step so I don't know how this makes sense as "two columns", assuming that you want each "row" to be a different time step. Instead I will use the following data structure: the final output will be an array with shape (T, N+1) where T is the number of time steps in the trajectory and N is the number of waters. Each row of the array contains [t, z1, z2, ..., zN], i.e., time and z-coordinate of water i.

    import numpy as np
    import MDAnalysis as mda
    
    u = mda.Universe(PSF, DCD)
    water_oxygens = u.select_atoms("name OW")
    
    # pre-allocate the array for the data
    data = np.zeros((u.trajectory.n_frames, water_oxygens.n_atoms + 1))
    
    for i, ts in enumerate(u.trajectory):
       data[i, 0] = ts.time                          # store current time
       data[i, 1:] = water_oxygens.positions[:, 2]   # extract all z-coordinates
    
    # now data contains your timeseries and you can work with it
    # (or export it using np.savetxt()
    

    For a introduction to MDAnalysis see the User Guide which also has a quickstart guide that explains selections and trajectory iteration.

    For further questions ask on the MDAnalysis Google group where you typically get the fastest answers.