mdanalysis icon indicating copy to clipboard operation
mdanalysis copied to clipboard

Selection fails for water

Open Nilavro opened this issue 3 years ago • 2 comments

Expected behavior

I am trying to calculate RDF between peptides between O. and water's H from the following group file. But it fails. It however works for SF4's H but not for the water's H. Can you please help with this ?

This code works and gives me the ref --

u = mda.Universe("md_20.gro") res60 = u.select_atoms('resid 1-26 and name O') water = u.select_atoms('resname SF4 and name H')

When I run this however it fails --

res60 = u.select_atoms('resid 1-26 and name O') water = u.select_atoms("name HW").select_atoms("resname SOL")

Actual behavior

The rdf is a all [nan]

I get the following error :

/network/rit/lab/welchlab/miniconda3/envs/dssp/lib/python3.9/site-packages/MDAnalysis/analysis/base.py:447: UserWarning: Reader has no dt information, set to 1.0 ps self.times[i] = ts.time /network/rit/lab/welchlab/miniconda3/envs/dssp/lib/python3.9/site-packages/MDAnalysis/analysis/rdf.py:293: RuntimeWarning: invalid value encountered in divide self.results.rdf = self.results.count / norm

Code to reproduce the behavior

import sys

import MDAnalysis as mda
from MDAnalysis.tests.datafiles import TPR, XTC
from MDAnalysis.analysis import rdf
import matplotlib.pyplot as plt
import pandas as pd


print ("how to run --- python run_rdf.py tpr_file.tpr xtc_file.xtc output_csv_name.csv rdf_img_name.png \n\n\n\n")

# Load the topology (TPR) file
#topology_file =  sys.argv[1]  # "./md_20.tpr"
#u = mda.Universe(topology_file)

# Load the trajectory (XTC) file
#trajectory_file = sys.argv[2] #  "./final_noPBC.xtc"
#u.load_new(trajectory_file)

# u = mda.Universe(TPR, XTC)

u = mda.Universe("md_20.gro")


res60 = u.select_atoms('resid 1-26  and name O')
water = u.select_atoms("name HW").select_atoms("resname SOL") # u.select_atoms('resname SOL and name HW')


#   print  ("Water  moleculesare: "+ water)

rdf_obj = rdf.InterRDF(res60, water,
                    nbins=100,  # default
                    range=(0.0, 8.0),  # distance in angstroms
                   )

rdf_obj.run()

# Get the bin edges
rdf = rdf_obj.results
bin_edges = rdf_obj.bins

plt.plot(rdf_obj.bins, rdf_obj.rdf)
plt.xlabel('Radius (angstrom)')
plt.ylabel('Radial distribution')

plt.legend()


plt.savefig(sys.argv[4])


df = pd.DataFrame(list(zip(rdf_obj.bins, rdf_obj.rdf)),
               columns =['Radius', 'RDF'])

df.to_csv(sys.argv[3])

# print(rdf_obj.bins)
print(rdf_obj.rdf)

Input File : Example

SF4 -

  563SF4     F1 9557   7.198   8.864   7.996  0.0593  0.0560 -0.4119
  563SF4     F2 9558   7.324   8.760   7.801  0.5531 -0.3245  0.0484
  563SF4     F3 9559   7.116   8.633   7.760 -0.5017 -0.0391  0.1816
  563SF4     C2 9560   7.236   8.600   7.982 -0.3489 -0.4833 -0.4548
  563SF4     F4 9561   7.324   8.663   8.066 -0.1353  0.0643  0.0409
  563SF4     F5 9562   7.302   8.514   7.904 -0.4424  0.1418 -0.1550
  563SF4     F6 9563   7.137   8.528   8.046  0.1820 -0.1335  0.3379
  564SF4      S 9564   6.553   3.666   8.000 -0.1429  0.0976 -0.1327
  564SF4      C 9565   6.478   3.523   8.098 -0.3800 -1.1458  0.7340
  564SF4     C1 9566   6.566   3.442   8.182 -0.9374  0.2124  0.7457
  564SF4      O 9567   6.504   3.333   8.250  0.4469 -0.4840  0.1646
  564SF4      H 9568   6.576   3.277   8.278 -0.8245 -2.0236  0.5035
  564SF4     H1 9569   6.625   3.386   8.108  0.0651  0.5477  1.2775
  564SF4     H2 9570   6.634   3.495   8.250 -0.3271  0.4857 -0.0635
  564SF4     H3 9571   6.425   3.484   8.012  0.1420  1.5707 -0.9674
  564SF4     H4 9572   6.397   3.562   8.159 -0.5961 -1.7391  0.8282
  564SF4      F 9573   6.410   3.675   7.908 -0.5048  0.4232 -0.5102

Water section

  966SOL     MW13060   5.884   5.281   3.396 -0.3595  0.0966  0.3424
  967SOL     OW13061   3.945   6.052   2.596  0.4192 -0.0256 -0.4491
  967SOL    HW113062   4.012   6.119   2.603 -0.6959  1.0177  0.6327
  967SOL    HW213063   3.936   6.017   2.685  0.1632 -0.7885 -0.7616
  967SOL     MW13064   3.952   6.056   2.608  0.2437  0.0105 -0.3505
  968SOL     OW13065   7.422   9.023   2.737 -0.7055  0.2535 -0.0367
  968SOL    HW113066   7.361   9.094   2.755 -3.5852 -2.0712  0.2189
  968SOL    HW213067   7.410   9.005   2.643  0.0090  0.1144 -0.1030
  968SOL     MW13068   7.413   9.030   2.727 -0.9828 -0.0620 -0.0126
  969SOL     OW13069   0.599   0.812   3.058  0.0998  0.4688 -0.0731
  969SOL    HW113070   0.630   0.889   3.106 -2.3497  0.2750  2.0335
  969SOL    HW213071   0.544   0.765   3.121 -0.7935 -1.4932 -2.1720
  969SOL     MW13072   0.596   0.816   3.072 -0.3281  0.1928 -0.0721
  970SOL     OW13073   6.595   1.786   0.387 -0.3733 -0.0767  0.5900
  970SOL    HW113074   6.521   1.807   0.443  0.2826 -0.9904  1.8367
  970SOL    HW213075   6.554   1.758   0.305 -1.3650  0.5313  0.8481
  970SOL     MW13076   6.580   1.785   0.383 -0.4165 -0.1158  0.7826
  971SOL     OW13077   0.885   0.023   0.162 -0.2601 -0.0539  0.4883
  971SOL    HW113078   0.804   0.065   0.132 -0.2617 -0.7949 -0.6363
  971SOL    HW213079   0.949   0.093   0.166 -0.7436  0.3900  0.5253
  971SOL     MW13080   0.882   0.037   0.158 -0.3222 -0.0919  0.3491
  972SOL     OW13081   7.677  10.212   8.228 -0.1356 -0.1417 -0.1841
  972SOL    HW113082   7.589  10.204   8.265 -0.2009 -1.4995 -0.5687
  972SOL    HW213083   7.663  10.215   8.133  0.2200 -0.0564 -0.2377
  972SOL     MW13084   7.664  10.211   8.221 -0.0985 -0.3052 -0.2408
  973SOL     OW13085   1.925   6.754   1.568 -0.0792 -0.5621  0.0975
  973SOL    HW113086   1.944   6.767   1.660  2.6432 -0.2624 -0.4302
  973SOL    HW213087   1.991   6.806   1.522 -2.4431  0.7619 -2.0605
  973SOL     MW13088   1.936   6.762   1.574 -0.0334 -0.3541 -0.2463
  974SOL     OW13089   1.922   9.416  10.492 -0.0965 -0.5025 -0.7393
  974SOL    HW113090   1.984   9.481  10.525 -0.5366 -1.8485  3.3575
  974SOL    HW213091   1.971   9.333  10.494 -0.8285 -0.9745 -1.5286
  974SOL     MW13092   1.937   9.413  10.497 -0.2466 -0.7353 -0.3161
  975SOL     OW13093   8.782   9.105   5.690  0.2579 -0.8415  0.4557
  975SOL    HW113094   8.820   9.019   5.708 -0.2712 -0.8998  1.3352
  975SOL    HW213095   8.789   9.115   5.595 -0.0388 -2.0308  0.2980
  975SOL     MW13096   8.788   9.096   5.680  0.1521 -1.0009  0.5481

Current version of MDAnalysis

  • Which version are you using? (run python -c "import MDAnalysis as mda; print(mda.__version__)") 2.5.0

  • Which version of Python (python -V)? 3.9

  • Which operating system? Linux

Nilavro avatar Jul 30 '23 21:07 Nilavro

@Nilavro could you try water = u.select_atoms("name HW*").select_atoms("resname SOL")? (Note the * after HW). Your SOL hydrogen atoms are actually named HW1 and HW2, not HW.

lilyminium avatar Aug 08 '23 02:08 lilyminium

@Nilavro please let us know if the above suggestion has not resolved your issue -- otherwise, we will close this in a couple days unless we get more information to work with.

lilyminium avatar Aug 14 '23 03:08 lilyminium