From 4d590b056f90f88df0a43fcb289b0fcb3fe69e81 Mon Sep 17 00:00:00 2001 From: Killian Sheriff Date: Tue, 8 Aug 2023 06:30:00 -0700 Subject: [PATCH] comments --- src/WarrenCowleyParameters/__init__.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/WarrenCowleyParameters/__init__.py b/src/WarrenCowleyParameters/__init__.py index 495840c..2708443 100644 --- a/src/WarrenCowleyParameters/__init__.py +++ b/src/WarrenCowleyParameters/__init__.py @@ -7,14 +7,17 @@ class WarrenCowleyParameters(ModifierInterface): + # List of integers representing the maximum number of atoms in shells nneigh = List(Int, value=[0, 12], label="Max atoms in shells", minlen=2) def validateInput(self): + # Check if the list of maximum atoms in shells is strictly increasing if not np.all(np.diff(self.nneigh) > 0): raise ValueError("'Max atoms in shells' must be strictly increasing.") @staticmethod def get_type_name(data, id): + # Get the name of a particle type by its ID ptype = data.particles["Particle Type"].type_by_id(id) name = ptype.name if name: @@ -23,11 +26,13 @@ def get_type_name(data, id): @staticmethod def get_concentration(particle_types): + # Calculate the concentration of unique particle types unique_types, counts = np.unique(particle_types, return_counts=True) return unique_types, counts / len(particle_types) @staticmethod def get_central_atom_type_mask(unique_types, particles_types): + # Create a mask for central atom types central_atom_type_mask = [] for atom_type in unique_types: central_atom_type_mask.append(np.where(particles_types == atom_type)) @@ -37,9 +42,9 @@ def get_central_atom_type_mask(unique_types, particles_types): def get_wc_from_neigh_in_shell_types( neigh_in_shell_types, central_atom_type_mask, c, unique_types ): + # Calculate Warren-Cowley parameters for atoms in shells ntypes = len(c) neight_in_shell = neigh_in_shell_types.shape[1] - wc = np.zeros((ntypes, ntypes)) for i in range(ntypes): @@ -56,8 +61,9 @@ def modify(self, data: DataCollection, frame: int, **kwargs): self.validateInput() particles_types = np.array(data.particles.particle_type) ntypes = len(np.unique(particles_types)) - max_number_of_neigh = np.max(self.nneigh) + + # Find nearest neighbors for each particle finder = NearestNeighborFinder(max_number_of_neigh, data) neigh_idx, _ = finder.find_all() @@ -67,6 +73,7 @@ def modify(self, data: DataCollection, frame: int, **kwargs): nshells = len(self.nneigh) - 1 wc_for_shells = np.zeros((nshells, ntypes, ntypes)) + # Calculate Warren-Cowley parameters for each shell for m in range(nshells): neigh_idx_in_shell = neigh_idx[:, self.nneigh[m] : self.nneigh[m + 1]] neigh_in_shell_types = particles_types[neigh_idx_in_shell] @@ -80,6 +87,8 @@ def modify(self, data: DataCollection, frame: int, **kwargs): labels = [] warrenCowley = [] idx = list(range(len(unique_types))) + + # Get labels and values for Warren-Cowley parameters for m in range(nshells): labels.append([]) warrenCowley.append([]) @@ -90,6 +99,7 @@ def modify(self, data: DataCollection, frame: int, **kwargs): labels[-1].append(f"{namei}-{namej}") warrenCowley[-1].append(wc_for_shells[m, i, j]) + # Create DataTable objects for visualization for m in range(nshells): table = DataTable( title=f"Warren-Cowley parameter: shell={m+1}", plot_mode=DataTable.PlotMode.BarChart