Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
killiansheriff committed Aug 8, 2023
1 parent 484728b commit 4d590b0
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/WarrenCowleyParameters/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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))
Expand All @@ -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):
Expand All @@ -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()

Expand 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]
Expand All @@ -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([])
Expand All @@ -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
Expand Down

0 comments on commit 4d590b0

Please sign in to comment.