Hi,
I would like to calculate the H bonds in the proteins of my simulation, but I am having trouble figuring out how to get the results and save them to a .dat file. Here is the code I have so far:
````
import MDAnalysis as mda
import numpy as np
from MDAnalysis.analysis.hydrogenbonds.hbond_analysis import HydrogenBondAnalysis as HBA
u = mda.Universe("J:/Wildtype_100ns_Test1_QwikMD.psf", "J:/MD.dcd")
hbonds = HBA(universe=u)
hbonds.hydrogens_sel = hbonds.guess_hydrogens("protein")
hbonds.acceptors_sel = hbonds.guess_acceptors("protein")
hbonds.run()
print(HBA.hbonds)
np.savetxt('hbonds_protein.dat', HBA.hbonds)
````
When I run that, this is the output:
<property object at 0x00000288F041DB30>
---------------------------------------------------------------------------
ValueError Traceback (most recent call last)
Input In [5], in <cell line: 14>()
11 hbonds.run()
13 print(HBA.hbonds)
---> 14 np.savetxt('hbonds_protein.dat', HBA.hbonds)
File <__array_function__ internals>:180, in savetxt(*args, **kwargs)
File ~\anaconda3\lib\site-packages\numpy\lib\npyio.py:1397, in savetxt(fname, X, fmt, delimiter, newline, header, footer, comments, encoding)
1395 # Handle 1-dimensional arrays
1396 if X.ndim == 0 or X.ndim > 2:
-> 1397 raise ValueError(
1398 "Expected 1D or 2D array, got %dD array instead" % X.ndim)
1399 elif X.ndim == 1:
1400 # Common case -- 1d array of numbers
1401 if X.dtype.names is None:
ValueError: Expected 1D or 2D array, got 0D array instead
I have also tried running this:
````
import MDAnalysis as mda
import numpy as np
from MDAnalysis.analysis.hydrogenbonds.hbond_analysis import HydrogenBondAnalysis as HBA
u = mda.Universe("J:/Wildtype_100ns_Test1_QwikMD.psf", "J:/MD.dcd")
hbonds = HBA(universe=u)
hbonds.hydrogens_sel = hbonds.guess_hydrogens("protein")
hbonds.acceptors_sel = hbonds.guess_acceptors("protein")
hbonds.run()
hbonds_results = np.array(HBA.hbonds)
print(hbonds_results)
np.savetxt('hbonds_protein.dat', hbonds_results)
````
But I get a similar error. What am I doing wrong?