Problems with Angle Distribution in water dynamics module

31 views
Skip to first unread message

Elías C

unread,
Nov 7, 2021, 11:00:12 AM11/7/21
to mdnalysis-...@googlegroups.com
Estimated MDAnalysis group. I would like to make an angle distribution analysis, so, I follow the tutorial presented in https://docs.mdanalysis.org/stable/documentation_pages/analysis/waterdynamics.html

A common warning that I have is:

/lib/python3.8/site-packages/MDAnalysis/analysis/hbonds/hbond_autocorrel.py:52: DeprecationWarning: This module was moved to MDAnalysis.analysis.hydrogenbonds.hbond_autocorrel; hbonds.hbond_autocorrel will be removed in 3.0.0.

But, it is not seen to be something problematic. In the original line:

for bin in range(bins):
        print("{AD_analysisOH} {AD_analysisHH} {AD_analysisDip}".format(AD_analysis.graph0=AD_analysis.graph[0][bin], AD_analysis.graph1=AD_analysis.graph[1][bin],AD_analysis.graph2=AD_analysis.graph[2][bin]))

I had by separate, after modificate the code, two errors:

1) print("{AD_analysisOH} {AD_analysisHH} {AD_analysisDip}".format(AD_analysis.graph0=AD_analysis.graph[0][bin], AD_analysis.graph1=AD_analysis.graph[1][bin],AD_analysis.graph2=AD_analysis.graph[2][bin]))
                                                                    ^
SyntaxError: expression cannot contain assignment, perhaps you meant "=="?

2) print("{AD_analysisOH} {AD_analysisHH} {AD_analysisDip}".format(AD_analysis.graph0==AD_analysis.graph[0][bin], AD_analysis.graph1==AD_analysis.graph[1][bin],AD_analysis.graph2==AD_analysis.graph[2][bin]))
AttributeError: 'AngularDistribution' object has no attribute 'graph0'

In my final code, modifications are highlighted with black::

for bin in range(bins):
      print("{AD_analysisOH} {AD_analysisHH} {AD_analysisDip}".format(AD_analysis.graph[0]==AD_analysis.graph[0][bin], AD_analysis.graph[1]==AD_analysis.graph[1][bin],AD_analysis.graph[2]==AD_analysis.graph[2][bin]))

After change that I get the next error:

print("{AD_analysisOH} {AD_analysisHH} {AD_analysisDip}".format(AD_analysis.graph[0]==AD_analysis.graph[0][bin], AD_analysis.graph[1]==AD_analysis.graph[1][bin],AD_analysis.graph[2]==AD_analysis.graph[2][bin]))
KeyError: 'AD_analysisOH'

I am not sure how to solve it. Thank you for your time and help.

Paul Smith

unread,
Nov 7, 2021, 12:05:59 PM11/7/21
to MDnalysis discussion
Hi,

I'm not very familiar with this module but I can try to help you out:

A common warning that I have is:
>     /lib/python3.8/site-packages/MDAnalysis/analysis/hbonds/hbond_autocorrel.py:52: DeprecationWarning: This module was moved to MDAnalysis.analysis.hydrogenbonds.hbond_autocorrel; hbonds.hbond_autocorrel will be removed in 3.0.0.

This is nothing to worry about. It's letting you know that the hbond_autocorrel module has been moved to a different location, so you would need to import it from MDAnalysis.analysis.hydrogenbonds instead of MDAnalysis.analysis.hbonds.

I had by separate, after modificate the code, two errors:
>     1) print("{AD_analysisOH} {AD_analysisHH} {AD_analysisDip}".format(AD_analysis.graph0=AD_analysis.graph[0][bin], AD_analysis.graph1=AD_analysis.graph[1][bin],AD_analysis.graph2=AD_analysis.graph[2][bin]))
            SyntaxError: expression cannot contain assignment, perhaps you meant "=="?

There's a couple of typos in the formatting of the string. I think it should be:

for bin in range(bins):
    print("{AD_analysisOH} {AD_analysisHH} {AD_analysisDip}".format(
        AD_analysisOH=AD_analysis.graph[0][bin],
        AD_analysisHH=AD_analysis.graph[1][bin],
        AD_analysisDip=AD_analysis.graph[2][bin])
    )

This is using string formatting with named parameters, e.g.:

    "{named_thing_1},  {named_thing_2}".format(named_thing_1=10, named_thing_2=20)

will create a string "10, 20".

Cheers,
Paul


Elías C

unread,
Nov 7, 2021, 12:18:48 PM11/7/21
to mdnalysis-...@googlegroups.com
Thank you very much! This has worked perfectly!

--
You received this message because you are subscribed to the Google Groups "MDnalysis discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mdnalysis-discus...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mdnalysis-discussion/bc8484e0-6f62-47f5-904a-dd63c9e176e5n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages