Coverage for gamdpy/tools/save_configuration.py: 14%
7 statements
« prev ^ index » next coverage.py v7.4.4, created at 2025-06-14 15:25 +0200
« prev ^ index » next coverage.py v7.4.4, created at 2025-06-14 15:25 +0200
3def save_configuration(configuration, filename:str, format="xyz", append=False):
4 """ Saves configuration to file.
6 Helpful for, e.g., VMD visualization
7 This current version only supports the standard xyz-format.
9 Example
10 -------
12 >>> import os
13 >>> import gamdpy as gp
14 >>> import numpy as np
15 >>> conf = gp.Configuration(D=3, N=10)
16 >>> gp.tools.save_configuration(configuration=conf, filename="final.xyz", format="xyz")
17 >>> os.remove("final.xyz") # Removes file (for doctests)
19 """
21 import numpy as np
22 append = "a" if append else "w"
24 if format=="xyz":
25 with open(filename, append) as f:
26 np.savetxt(f, np.c_[configuration.ptype, configuration['r']],
27 header=f"{configuration.N}\n#Position xyz format - generated by gamdpy", comments="")
28 else:
29 raise ValueError("Format not supported")