Skip to content

Commit e6a5a51

Browse files
robinzybCopilot
andauthored
Refactor atom density class (#48)
* Refactor Atoms_density class to AnalysisBase * move the deprecated density class to bottom * add doc for new atom density class * Update tests/analysis/atom_density/test_atom_density.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update docs/analysis/atom_density.md Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 08f4688 commit e6a5a51

3 files changed

Lines changed: 424 additions & 125 deletions

File tree

docs/analysis/atom_density.md

Lines changed: 57 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,16 @@ Next, we move to the analysis of water density at interfaces.
4444
To perform the water density analysis, the indices of oxygen atoms between two interfaces are need to be specified, as shown in the `O_idx` of the above figure. Again, you can find the indices using the method `find_idx_from_range`, and put these indices (`List`) in the `inp_dict["density_type"]["idx_list"]`. Here, the `density_unit` should be set to `"water"` because the coordinates of oxygen atoms are treated as the positions of water molecules and are converted to water density through unit conversion.
4545

4646
## Usage
47-
Now, we import the analysis class `AtomDensity` and gather the following mentioned parameters.
47+
Now, we import the analysis class `AtomDensity` and gather the above mentioned parameters into a dictionary `inp`. Because the `AtomDensity` class is based on the `AnalysisBase` class from the MDAnalysis package, an `Universe` object is necessary to use the class.
48+
We recommend that users instantiate an `Universe` object by themselves as follows. The dictionary `inp` is not required.
4849
```python
4950
from ectoolkits.analysis.atom_density import AtomDensity
5051

51-
# from
52-
inp_dict={
52+
# The following input
53+
inp={
5354
"xyz_file": "./Hematite-pos-1.xyz", # the path to the xyz trajecotry.
55+
"format": "XYZ", # could be other formats for trajectories. Please refer to MDAnalysis
56+
# https://userguide.mdanalysis.org/stable/formats/index.html#id1
5457
"cell": [10.0564, 8.7091, 38.506, 90, 90, 90], # the cell parameters
5558
"surf2": [32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43], # the interface on the right
5659
"surf1": [112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 12], # the interface on the left
@@ -74,9 +77,22 @@ inp_dict={
7477
]
7578
}
7679

77-
ad = AtomDensity(inp_dict)
80+
xyz_file = inp.get("xyz_file")
81+
fmt = inp.get("format", "XYZ")
82+
cell = inp.get("cell")
83+
cell = Cell.new(cell)
84+
u = Universe(xyz_file, format=fmt)
85+
u.atoms.dimensions = cell.cellpar()
86+
surf1 = inp.get("surf1")
87+
surf2 = inp.get("surf2")
88+
density_type = inp.get("density_type")
89+
ad = AtomDensity(atomgroup=u.atoms,
90+
surf1=surf1,
91+
surf2=surf2,
92+
density_type=density_type)
7893
ad.run()
7994

95+
8096
# detail information is accessible in
8197
ad.atom_density
8298
ad.atom_density_z
@@ -90,4 +106,40 @@ all_cent_density = ad.get_ave_density(width_list)
90106
ad.plot_density(sym=False)
91107

92108
```
93-
![density](./figures/density.png)
109+
![density](./figures/density.png)
110+
111+
112+
113+
114+
## Old inputs
115+
For users using the following old input. We recommend use the function `run_atom_density_analysis` to parse the input. The usage is present as follows:
116+
```python
117+
from ectoolkits.analysis.atom_density import run_atom_density_analysis
118+
119+
# from
120+
inp_dict={
121+
"xyz_file": "./Hematite-pos-1.xyz", # the path to the xyz trajecotry.
122+
"cell": [10.0564, 8.7091, 38.506, 90, 90, 90], # the cell parameters
123+
"surf2": [32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43], # the interface on the right
124+
"surf1": [112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 12], # the interface on the left
125+
"density_type":[
126+
{
127+
"element": "O",
128+
"idx_method": "manual",
129+
"idx_list": O_idx,
130+
"density_unit": "water",
131+
"dz": 0.05,
132+
"name": "O_density"
133+
},
134+
{
135+
"element": "H",
136+
"idx_method": "manual",
137+
"idx_list": H_idx,
138+
"density_unit": "water",
139+
"dz": 0.05,
140+
"name": "H_density"
141+
}
142+
]
143+
}
144+
145+
ad = run_atom_density_analysis(input_dict)

0 commit comments

Comments
 (0)