|
10 | 10 | from MDAnalysis.analysis.base import AnalysisBase |
11 | 11 | from MDAnalysis.lib.mdamath import box_volume |
12 | 12 |
|
| 13 | +import matplotlib as mpl |
| 14 | +import cp2kdata.plots.colormaps |
| 15 | + |
13 | 16 | from ectoolkits.structures.slab import Slab |
14 | 17 | from ectoolkits.utils.utils import mic_1d |
15 | 18 | from ectoolkits.log import get_logger |
@@ -365,7 +368,41 @@ def get_unit_conversion(density_unit, dz, xy_area): |
365 | 368 |
|
366 | 369 | return unit_conversion |
367 | 370 |
|
| 371 | + def get_ave_density(self, width_list): |
| 372 | + all_cent_density = {} |
| 373 | + all_cent_density[f"width"] = width_list |
| 374 | + for name, density in self.atom_density.items(): |
| 375 | + z = self.atom_density_z[name] |
| 376 | + cent = z[-1]/2 |
| 377 | + cent_density_list = [] |
| 378 | + for width in width_list: |
| 379 | + left_bound = cent - width/2 |
| 380 | + right_bound = cent + width/2 |
| 381 | + part_density = density[np.logical_and( |
| 382 | + (z >= left_bound), (z <= right_bound))] |
| 383 | + cent_density = part_density.mean() |
| 384 | + cent_density_list.append(cent_density) |
368 | 385 |
|
| 386 | + all_cent_density[f"{name}"] = cent_density_list |
| 387 | + |
| 388 | + return pd.DataFrame(all_cent_density) |
| 389 | + |
| 390 | + def plot_density(self, sym=False): |
| 391 | + plt.style.use('cp2kdata.matplotlibstyle.jcp') |
| 392 | + cp2kdata_cb_lcmap = mpl.colormaps['cp2kdata_cb_lcmap'] |
| 393 | + plt.rcParams["axes.prop_cycle"] = plt.cycler("color", cp2kdata_cb_lcmap.colors) |
| 394 | + fig = plt.figure(figsize=(3.37, 1.89), dpi=400, facecolor='white') |
| 395 | + ax = fig.add_subplot() |
| 396 | + for name, density in self.atom_density.items(): |
| 397 | + z = self.atom_density_z[name] |
| 398 | + density = density |
| 399 | + if sym: |
| 400 | + density = (np.flip(density) + density)/2 |
| 401 | + ax.plot(z, density, label=name) |
| 402 | + ax.legend() |
| 403 | + ax.set_ylabel("Density") |
| 404 | + ax.set_xlabel(r"z ($\mathrm{\AA}$)") |
| 405 | + return fig |
369 | 406 |
|
370 | 407 |
|
371 | 408 | # old density analysis function/class |
|
0 commit comments