Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set default charge/spin if not given in .xyz file #56

Merged
merged 1 commit into from
Dec 11, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src/qibochem/driver/molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
else:
# Check if xyz_file exists, then fill in the Molecule attributes
assert Path(f"{xyz_file}").exists(), f"{xyz_file} not found!"
self._process_xyz_file(xyz_file)
self._process_xyz_file(xyz_file, charge, multiplicity)

Check warning on line 45 in src/qibochem/driver/molecule.py

View check run for this annotation

Codecov / codecov/patch

src/qibochem/driver/molecule.py#L45

Added line #L45 was not covered by tests
if basis is None:
# Default bais is STO-3G
self.basis = "sto-3g"
Expand Down Expand Up @@ -80,7 +80,7 @@
self.n_active_e = None
self.n_active_orbs = None # Number of spin-orbitals in the active space

def _process_xyz_file(self, xyz_file):
def _process_xyz_file(self, xyz_file, charge, multiplicity):
"""
Reads a .xyz file to obtain and set the molecular coordinates (in OpenFermion format),
charge, and multiplicity
Expand All @@ -91,7 +91,15 @@
with open(xyz_file, encoding="utf-8") as file_handler:
# First two lines: # atoms and comment line (charge, multiplicity)
_n_atoms = int(file_handler.readline()) # Not needed/used
_charge, _multiplicity = (int(_num) for _num in file_handler.readline().split())

# Try to read charge and multiplicity from comment line
split_line = [int(_num) for _num in file_handler.readline().split()]
if len(split_line) == 2:

Check warning on line 97 in src/qibochem/driver/molecule.py

View check run for this annotation

Codecov / codecov/patch

src/qibochem/driver/molecule.py#L96-L97

Added lines #L96 - L97 were not covered by tests
# Format of comment line matches (charge, multiplicity):
_charge, _multiplicity = split_line

Check warning on line 99 in src/qibochem/driver/molecule.py

View check run for this annotation

Codecov / codecov/patch

src/qibochem/driver/molecule.py#L99

Added line #L99 was not covered by tests
else:
# Otherwise, use the default (from __init__) values of 0 and 1
_charge, _multiplicity = charge, multiplicity

Check warning on line 102 in src/qibochem/driver/molecule.py

View check run for this annotation

Codecov / codecov/patch

src/qibochem/driver/molecule.py#L102

Added line #L102 was not covered by tests

# Start reading xyz coordinates from the 3rd line onwards
_geometry = []
Expand Down