Skip to content

Commit

Permalink
MAINT: Convert to using np.atleast_2d
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-rocke committed Jun 13, 2024
1 parent 15220f2 commit 09846da
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions matscipy/dislocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -2618,24 +2618,37 @@ def _build_bulk_cyl(self, radius, core_positions, fix_rad, extension,
Bulk cyl, cut down based on radius, complete
with FixAtoms constraints
'''
from matscipy.utils import radial_mask_from_polygon2D

if self_consistent is None:
self_consistent = self.self_consistent

# Validate core position, extension, and fixed_points args
errs = []
for argname, arg in [["core_position", core_positions], ["extension", extension], ["fixed_points", fixed_points]]:
def enforce_arr_shape(argname, arg, errs):
'''
Enforce correct array dimensionality for
'''
if type(arg) == np.ndarray:
if arg.shape[-1] != 3:
# Needs to be 3d vectors
errs.append(f"Argument {argname} misspecified. Should be an array of shape (N, 3)")
if len(arg.shape) == 1:
# Convert all arrays to 2D
arg.reshape((np.newaxis, arg.shape[-1]))
arg = np.atleast_2d(arg)
elif arg is not None:
# non-array, and not None arg provided, which is not allowed
errs.append(f"Argument {argname} misspecified. Should be an array of shape (N, 3)")
return arg, errs


from matscipy.utils import radial_mask_from_polygon2D

if self_consistent is None:
self_consistent = self.self_consistent

# Validate core position, extension, and fixed_points args
errs = []

core_positions, errs = enforce_arr_shape("core_positions", core_positions, errs)
extension, errs = enforce_arr_shape("extension", extension, errs)
fixed_points, errs = enforce_arr_shape("fixed_points", fixed_points, errs)

if len(errs):
raise RuntimeError("\n".join(errs))

Expand Down Expand Up @@ -2953,6 +2966,10 @@ def build_glide_configurations(self, radius, average_positions=False, **kwargs):

fixed_points = np.vstack([initial_core_position, final_core_position])

if "partial_distance" in kwargs.keys():
# Account for dissociated glide
fixed_points[1, 0] += kwargs["partial_distance"] * self.glide_distance

bulk_ini, disloc_ini, cyl_mask = self.build_cylinder(radius,
core_position=initial_core_position,
fixed_points=fixed_points,
Expand Down

0 comments on commit 09846da

Please sign in to comment.