35__all__ = ("convert",)
36
37
38DESCRIPTION = """\ 39Convert between file formats supported by IOData. This only works if the input
40contains sufficient data for the output.
41
85 A temporary directory where the truncated file is stored.
86
87 """
88 fn_truncated = "%s/truncated_%i_%s" % (tmpdir, nline, os.path.basename(fn_orig)) 89 with open(fn_orig) as f_orig, open(fn_truncated, "w") as f_truncated:
90 for counter, line in enumerate(f_orig):
91 if counter >= nline:
619def dump_one(f: TextIO, data: IOData):
620 """Do not edit this docstring. It will be overwritten."""
621 # write title
622 print("{:72}".format(data.title or "FCHK generated by IOData"), file=f)623
624 # write run type, level of theory, and basis set name (all in uppercase)
625 items = [getattr(data, item) or "NA" for item in ["run_type", "lot", "obasis_name"]]
866 if last_icenter != -1:
867 f.write("\n")
868 last_icenter = shell.icenter
869 f.write("%3i 0\n" % (shell.icenter + 1))870 # Write out the basis.
871 # It is guaranteed to be segmented when reaching this part of the code.
872 angmom = shell.angmoms[0]
376 )
377 if occupations.max() > occ_max + eps:
378 raise ValueError(
379 "The density matrix has eigenvalues considerably larger than "380 "max. error=%e" % (occupations.max() - 1)
381 )
382
f-strings are the fastest way to format strings as compared to the following methods:
%
format()
str.join
+
operator to concatinate stringTemplate.substitute
Some less preferred ways to format strings are the following:
from string import Template
menu = ('eggs', 'spam', 42.4)
old_order = "%s and %s: %.2f ¤" % menu # [consider-using-f-string]
beginner_order = menu[0] + " and " + menu[1] + ": " + str(menu[2]) + " ¤"
joined_order = " and ".join(menu[:2])
format_order = "{} and {}: {:0.2f} ¤".format(menu[0], menu[1], menu[2])
named_format_order = "{eggs} and {spam}: {price:0.2f} ¤".format(eggs=menu[0], spam=menu[1], price=menu[2])
template_order = Template('$eggs and $spam: $price ¤').substitute(eggs=menu[0], spam=menu[1], price=menu[2])
Consider using f-strings as shown below:
menu = ('eggs', 'spam', 42.4)
f_string_order = f"{menu[0]} and {menu[1]}: {menu[2]:0.2f} ¤"