-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add outputs to waterdynamics.AngularDistribution ? #21
Comments
For now, I have create a function based on import numpy as np
from MDAnalysis.lib.log import ProgressBar
#### from _getCosTheta of MDAnalysis.analysis.waterdynamics.AngularDistribution
def getCosTheta(selection, axis):
line = selection.positions
Ot0 = line[::3]
H1t0 = line[1::3]
H2t0 = line[2::3]
RH2O = np.linalg.norm(Ot0[:,0:2], axis=1)
OHVector0 = H1t0 - Ot0
HHVector0 = H1t0 - H2t0
dipVector0 = (H1t0 + H2t0) * 0.5 - Ot0
unitOHVector0 = OHVector0 / np.linalg.norm(OHVector0, axis=1)[:, None]
unitHHVector0 = HHVector0 / np.linalg.norm(HHVector0, axis=1)[:, None]
unitdipVector0 = dipVector0 / np.linalg.norm(dipVector0, axis=1)[:, None]
if axis == "z":
valOH = (unitOHVector0[:,2])
valHH = (unitHHVector0[:,2])
valdip = (unitdipVector0[:,2])
elif axis == "x":
valOH = (unitOHVector0[:,0])
valHH = (unitHHVector0[:,0])
valdip = (unitdipVector0[:,0])
elif axis == "y":
valOH.append(unitOHVector0[:,1])
valHH.append(unitHHVector0[:,1])
valdip.append(unitdipVector0[:,1])
return (valOH, valHH, valdip, RH2O)
cosOH, cosHH, cosdip, RH2O = [], [] , [], []
for ts in ProgressBar(u.trajectory, verbose=True, total=u.trajectory.n_frames):
valOH, valHH, valdip, rH2O = getCosTheta(H2O.ts, 'z')
cosOH = np.append(cosOH, valOH)
cosHH = np.append(cosHH, valHH)
cosdip = np.append(cosdip, valdip)
RH2O = np.append(RH2O, rH2O)
|
Hi Yann, thanks for your suggestions! I'm glad you found a solution that works for you. We always welcome suggestions for API changes, however as I am not the author or a heavy user of |
You're very welcome to propose changes. We definitely like code being cleaned up and modularized. We (or rather: our users) don't generally like breaking existing code so we tend to minimize any API breaks. But if you find a way to maintain the existing code from the user perspective (even though it might change under the hood) while at the same time adding new functionality then that would be interesting. Typically we can really only give more detailed feedback when we see code so the best way forward is to put up a pull request. At this point we see what your idea is and we can point out issues in the broader context of MDAnalysis, if we see any. We'll then also see what new tests would be needed. There's no guarantee that we add code although from past experience, most PRs will eventually get merged if the author remains committed to seeing them through until the end. But it can be a long-ish process because we want to maintain high code quality and minimize technical debt. |
I think, in order to keep the existing code and add new functionnality would be to modify the _getCosTheta so that it can be accessed "outside" the function.
return I will create a PR as you suggested. |
Hello,
The
angularDistribution
(AD) class gives too "high level" information according to me. Here is what I mean:I would like to plot a 2D histogram representing$\theta(\mu, \vec{R})$ where $\mu$ is the dipolar moment of water molecules and $\vec{R}$ the radial position with respect to z-axis.
My point is that, I would to see how water molecules are oriented when they are close to the interface (water molecules in a meso-porous material).
I do not see how I can achieve that with angularDistribution (AD). Even if it wasn't exactly what I would like to do, I tried to select atoms near the interface, however the cylayer keywords doesn't select the whole molecules (using it, I do not have 2 H for 1 O). Maybe is there a way to say "if atoms with molecule ID ("resid XXX" in my case) is in cylayer, then select all the atoms with the same molecule ID" ? But still, it would'nt be exactly what I am looking for (but a possible workaround).
I think, it would be more general if AD output could be similar to$\theta$ >
hbonds class
:<O index, O x-position, O y-position, O z-position,
Then it would be our responsability to plot an histogram, as it is with hbonds, and why not propose the actual AD class as a "higher level" .
For instance, with hbonds, I did this:
I would like to do something similar but with the dipolar-moment orientation.
Thanks,
Yann
The text was updated successfully, but these errors were encountered: