@@ -64,30 +64,20 @@ def _pprint(matrix):
64
64
65
65
66
66
def xyz2struct (molecule ):
67
- """Convert pymatgen molecule to dummy pymatgen structure"""
68
-
69
- alat , blat , clat = 1 , 1 , 1
70
-
71
- # Set the lattice dimensions in each direction
72
- for i in range (len (molecule ) - 1 ):
73
- if molecule .cart_coords [i ][0 ] > molecule .cart_coords [i + 1 ][0 ]:
74
- alat = molecule .cart_coords [i ][0 ]
75
- if molecule .cart_coords [i ][1 ] > molecule .cart_coords [i + 1 ][1 ]:
76
- blat = molecule .cart_coords [i ][1 ]
77
- if molecule .cart_coords [i ][2 ] > molecule .cart_coords [i + 1 ][2 ]:
78
- clat = molecule .cart_coords [i ][2 ]
79
-
80
- # Set the lattice dimensions in each direction
67
+ """Convert pymatgen molecule to dummy pymatgen structure using vectorized calculation."""
68
+ # Ensure the coordinates are in a NumPy array
69
+ coords = np .array (molecule .cart_coords )
70
+
71
+ # Compute maximum coordinate along each axis
72
+ alat , blat , clat = np .max (coords , axis = 0 )
73
+
81
74
lattice = Lattice .from_parameters (
82
75
a = alat , b = blat , c = clat , alpha = 90 , beta = 90 , gamma = 90
83
76
)
84
-
77
+
85
78
# Create a list of species
86
79
species = [Element (sym ) for sym in molecule .species ]
87
-
88
- # Create a list of coordinates
89
- coords = molecule .cart_coords
90
-
80
+
91
81
# Create the Structure object
92
82
struct = Structure (lattice , species , coords , coords_are_cartesian = True )
93
83
return struct
0 commit comments