Skip to content

Commit

Permalink
Merge pull request #44 from TREX-CoE/crystal2trexio-convert-from
Browse files Browse the repository at this point in the history
Crystal to TREXIO converter via CLI
  • Loading branch information
kousuke-nakano authored Nov 9, 2024
2 parents 24035f0 + cc94440 commit 9d7b794
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
trexio convert-from -t pyscf -i data/water.chk -b hdf5 trexio_pyscf_h2o_sph.h5
trexio convert-from -t pyscf -i data/diamond_single_k.chk -b hdf5 trexio_pyscf_1k.h5
trexio convert-from -t pyscf -i data/diamond_k_grid.chk -b hdf5 trexio_pyscf_Nk.h5
trexio convert-from -t crystal -i data/crystal23_mgo_lda.out -m 1 -b hdf5 crystal.hdf5
trexio convert-from -t orca -i data/h2o.json -b hdf5 trexio_orca_h2o_sph.h5
trexio convert-to -t cartesian -o trexio_orca_h2o.h5 trexio_orca_h2o_sph.h5
trexio convert-to -t cartesian -o trexio_pyscf_h2o.h5 trexio_pyscf_h2o_sph.h5
Expand Down
10 changes: 6 additions & 4 deletions src/trexio_tools/converters/convert_from.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

from .pyscf_to_trexio import pyscf_to_trexio as run_pyscf
from .orca_to_trexio import orca_to_trexio as run_orca
from .crystal_to_trexio import crystal_to_trexio as run_crystal

try:
import trexio
Expand Down Expand Up @@ -756,7 +757,7 @@ def run_molden(trexio_file, filename, normalized_basis=True, multiplicity=None,
trexio.write_mo_coefficient(trexio_file, MoMatrix)


def run(trexio_filename, filename, filetype, back_end, motype=None):
def run(trexio_filename, filename, filetype, back_end, spin=None, motype=None):

if os.path.exists(trexio_filename):
print(f"TREXIO file {trexio_filename} already exists and will be removed before conversion.")
Expand All @@ -778,9 +779,10 @@ def run(trexio_filename, filename, filetype, back_end, motype=None):
elif filetype.lower() == "orca":
back_end_str = "text" if back_end==trexio.TREXIO_TEXT else "hdf5"
run_orca(filename=trexio_filename, orca_json=filename, back_end=back_end_str)
elif filetype.lower() == "fcidump":
raise NotImplementedError(f"Conversion from {filetype} to TREXIO is not supported.")
#run_fcidump(trexio_file, filename)
elif filetype.lower() == "crystal":
if spin is None: raise ValueError("You forgot to provide spin for the CRYSTAL->TREXIO converter.")
back_end_str = "text" if back_end==trexio.TREXIO_TEXT else "hdf5"
run_crystal(trexio_filename=trexio_filename, crystal_output=filename, back_end=back_end_str, spin=spin)
elif filetype.lower() == "molden":
run_molden(trexio_file, filename)
else:
Expand Down
10 changes: 7 additions & 3 deletions src/trexio_tools/trexio_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
trexio check-basis [-n N_POINTS] [-b BACK_END] TREXIO_FILE
trexio check-mos [-n N_POINTS] [-b BACK_END] TREXIO_FILE
trexio convert-to -t TYPE -o OUTPUT_FILE [-y SPIN_ORDER] TREXIO_FILE
trexio convert-from -t TYPE -i INPUT_FILE [-b BACK_END] [-x MO_TYPE] TREXIO_FILE
trexio convert-from -t TYPE -i INPUT_FILE [-b BACK_END] [-x MO_TYPE] [-m MULTIPLICITY] TREXIO_FILE
trexio convert-backend -i INPUT_FILE -o OUTPUT_FILE -b BACK_END -j TREX_JSON_FILE [-s BACK_END_FROM] [-w OVERWRITE]
trexio (-h | --help)
Expand All @@ -17,9 +17,10 @@
-o, --output=OUTPUT_FILE Name of the output file.
-b, --back_end=BACK_END [hdf5 | text | auto] The TREXIO back end. [default: hdf5]
-s, --back_end_from=BACK_END [hdf5 | text | auto] The input TREXIO back end. [default: auto]
-m, --multiplicity=MULTIPLICITY Spin multiplicity for the Crystal converter.
-j, --json=TREX_JSON_FILE TREX configuration file (in JSON format).
-w, --overwrite=OVERWRITE Overwrite flag for the conversion of back ends. [default: True]
-t, --type=TYPE [gaussian | gamess | pyscf | orca | fcidump | molden | cartesian ] File format.
-t, --type=TYPE [gaussian | gamess | pyscf | orca | crystal | fcidump | molden | cartesian ] File format.
-x, --motype=MO_TYPE Type of the molecular orbitals. For example, GAMESS has RHF, MCSCF, GUGA, and Natural as possible MO types.
-y, --spin_order=TYPE [block | interleave] How to organize spin orbitals when converting to FCIDUMP [default: block]
"""
Expand Down Expand Up @@ -73,6 +74,9 @@ def main(filename=None, args=None):
else:
back_end_from = trexio.TREXIO_AUTO

spin = None
if args["--multiplicity"]:
spin = int(args["--multiplicity"])

if args["check-basis"]:
trexio_file = trexio.File(filename, 'r', back_end=back_end)
Expand All @@ -92,7 +96,7 @@ def main(filename=None, args=None):

elif args["convert-from"]:
from .converters.convert_from import run
run(args["TREXIO_FILE"], args["--input"], args["--type"], back_end=back_end, motype=args["--motype"])
run(args["TREXIO_FILE"], args["--input"], args["--type"], back_end=back_end, spin=spin, motype=args["--motype"])

elif args["convert-to"]:
from .converters.convert_to import run
Expand Down

0 comments on commit 9d7b794

Please sign in to comment.