|
19 | 19 | write_gen_file, |
20 | 20 | read_gen_file, |
21 | 21 | ) |
22 | | -from .restart_file.api import read_restart_file |
| 22 | +from .restart_file.api import ( |
| 23 | + read_restart_file, |
| 24 | + write_restart_file |
| 25 | +) |
23 | 26 | from .traj_file.api import write_trajectory |
24 | 27 |
|
25 | 28 |
|
26 | | - |
27 | 29 | @runtime_type_checking |
28 | 30 | def gen2xyz( |
29 | 31 | gen_file: str, |
@@ -65,7 +67,6 @@ def gen2xyz( |
65 | 67 | ) |
66 | 68 |
|
67 | 69 |
|
68 | | - |
69 | 70 | @runtime_type_checking |
70 | 71 | def xyz2gen( |
71 | 72 | xyz_file: str, |
@@ -110,7 +111,6 @@ def xyz2gen( |
110 | 111 | ) |
111 | 112 |
|
112 | 113 |
|
113 | | - |
114 | 114 | @runtime_type_checking |
115 | 115 | def rst2xyz( |
116 | 116 | restart_file: str, |
@@ -152,6 +152,75 @@ def rst2xyz( |
152 | 152 | ) |
153 | 153 |
|
154 | 154 |
|
| 155 | +@runtime_type_checking |
| 156 | +def xyz2rst( |
| 157 | + xyz_file: str, |
| 158 | + velocity_file: str | None = None, |
| 159 | + force_file: str | None = None, |
| 160 | + randomize: float = 0.0, |
| 161 | + random_seed: int | None = 0, |
| 162 | + output: str | None = None, |
| 163 | + md_format: MDEngineFormat | str = MDEngineFormat.PQ, |
| 164 | + mode: FileWritingMode | str = "w" |
| 165 | +) -> None: |
| 166 | + """ |
| 167 | + Converts a xyz file to a restart file and prints it to stdout or writes it to a file. |
| 168 | +
|
| 169 | + When the print_box flag is set to True, the box is printed as well. |
| 170 | + This means that after the number of atoms the box is printed in the |
| 171 | + same line in the format a b c alpha beta gamma. |
| 172 | +
|
| 173 | + Parameters |
| 174 | + ---------- |
| 175 | + xyz_file : str |
| 176 | + The xyz file to be converted. |
| 177 | + velocity_file : str | None |
| 178 | + The velocity file to be converted. Default is None. |
| 179 | + force_file : str | None |
| 180 | + The force file to be converted. Default is None. |
| 181 | + randomize : float, optional |
| 182 | + Randomize the atom order. Default is 0.0. |
| 183 | + output : str | None |
| 184 | + The output file. If not specified, the output is printed to stdout. |
| 185 | + md_format : MDEngineFormat | str, optional |
| 186 | + The format of the md engine for the output file. The default is MDEngineFormat.PQ. |
| 187 | + mode : FileWritingMode | str, optional |
| 188 | + The writing mode, by default "w". The following modes are available: |
| 189 | + - "w": write |
| 190 | + - "a": append |
| 191 | + - "o": overwrite |
| 192 | + """ |
| 193 | + |
| 194 | + system = TrajectoryReader( |
| 195 | + xyz_file, |
| 196 | + md_format=md_format, |
| 197 | + traj_format="xyz", |
| 198 | + ).read()[-1] |
| 199 | + |
| 200 | + if velocity_file is not None: |
| 201 | + system.vel = TrajectoryReader( |
| 202 | + velocity_file, |
| 203 | + md_format=md_format, |
| 204 | + traj_format="vel", |
| 205 | + ).read()[-1].vel |
| 206 | + |
| 207 | + if force_file is not None: |
| 208 | + system.forces = TrajectoryReader( |
| 209 | + force_file, |
| 210 | + md_format=md_format, |
| 211 | + traj_format="force", |
| 212 | + ).read()[-1].forces |
| 213 | + |
| 214 | + if randomize != 0.0: |
| 215 | + system.randomize_positions(stdev=randomize, seed=random_seed) |
| 216 | + |
| 217 | + write_restart_file( |
| 218 | + atomic_system=system, |
| 219 | + filename=output, |
| 220 | + md_engine_format=md_format, |
| 221 | + mode=mode, |
| 222 | + ) |
| 223 | + |
155 | 224 |
|
156 | 225 | @runtime_type_checking |
157 | 226 | def traj2box( |
@@ -201,7 +270,6 @@ def traj2box( |
201 | 270 | writer.write(trajectory, reset_counter=False) |
202 | 271 |
|
203 | 272 |
|
204 | | - |
205 | 273 | @runtime_type_checking |
206 | 274 | def traj2qmcfc( |
207 | 275 | trajectory_files: List[str], |
|
0 commit comments