@@ -31,18 +31,39 @@ def add_void_particles(
31
31
"""
32
32
void_axis = np .asarray (void_axis )
33
33
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
36
43
)
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
40
62
lj = [i for i in forcefield if isinstance (i , hoomd .md .pair .LJ )][0 ]
41
63
for ptype in snapshot .particles .types :
42
64
lj .params [(ptype , "VOID" )] = {
43
65
"sigma" : void_diameter ,
44
66
"epsilon" : epsilon ,
45
67
}
46
68
lj .r_cut [(ptype , "VOID" )] = r_cut
47
-
48
69
return snapshot , forcefield
0 commit comments