Skip to content

Commit 5b20dbb

Browse files
committed
merge fixes to void particle method
2 parents a337c3c + c0c60a4 commit 5b20dbb

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

flowermd/modules/welding/utils.py

+27-6
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,39 @@ def add_void_particles(
3131
"""
3232
void_axis = np.asarray(void_axis)
3333
snapshot.particles.N += num_voids
34-
snapshot.particles.position[-1] = (
35-
void_axis * snapshot.configuration.box[0:3] / 2
34+
# Set updated positions
35+
void_pos = void_axis * snapshot.configuration.box[0:3] / 2
36+
init_pos = snapshot.particles.position
37+
new_pos = np.empty((init_pos.shape[0] + 1, 3))
38+
new_pos[: init_pos.shape[0]] = init_pos
39+
new_pos[-1] = void_pos
40+
# snapshot.particles.position = new_pos
41+
snapshot.particles.position = np.concatenate(
42+
(init_pos, void_pos.reshape(1, 3)), axis=0
3643
)
37-
snapshot.particles.types = snapshot.particles.types + ["VOID"]
38-
snapshot.particles.typeid[-1] = len(snapshot.particles.types) - 1
39-
snapshot.particles.mass[-1] = 1
44+
45+
# Set updated types and type IDs
46+
snapshot.particles.types.append("VOID")
47+
void_id = len(snapshot.particles.types) - 1
48+
init_ids = snapshot.particles.typeid
49+
snapshot.particles.typeid = np.concatenate(
50+
(init_ids, np.array([void_id])), axis=None
51+
)
52+
# Set updated mass and charges
53+
init_mass = snapshot.particles.mass
54+
snapshot.particles.mass = np.concatenate(
55+
(init_mass, np.array([1])), axis=None
56+
)
57+
init_charges = snapshot.particles.charge
58+
snapshot.particles.charge = np.concatenate(
59+
(init_charges, np.array([0])), axis=None
60+
)
61+
# Updated LJ params
4062
lj = [i for i in forcefield if isinstance(i, hoomd.md.pair.LJ)][0]
4163
for ptype in snapshot.particles.types:
4264
lj.params[(ptype, "VOID")] = {
4365
"sigma": void_diameter,
4466
"epsilon": epsilon,
4567
}
4668
lj.r_cut[(ptype, "VOID")] = r_cut
47-
4869
return snapshot, forcefield

0 commit comments

Comments
 (0)