Molara-Lab / Molara

Molara is a Python package for the visualization of chemical structures such as molecules or crystals. It provides a graphical user interface for importing structures from output files of popular computational chemistry software as well as for creating custom structures.
GNU General Public License v3.0
14 stars 0 forks source link

Increase coverage of structure/io #469

Closed adrianusler closed 1 month ago

adrianusler commented 1 month ago

1.) exporter.py, GeneralExporter.__init__:

try:
    self._importer = self._IMPORTER_BY_SUFFIX[suffix](path)
except KeyError:
    try:
        self._importer = XyzExporter(path)
    except FileFormatError as err:
        msg = "Could not open file."
        raise FileFormatError(msg) from err

Everything in the except block is not covered.

2.) importer.py, XyzImporter._molecule_from_xyz:

for line in lines[2 : 2 + num_atoms]:
    atom_info = line.split()
    if atom_info[0].isnumeric():
        atomic_numbers.append(int(atom_info[0]))
    ...

The isnumeric() case is not covered. Probably requires new input files for the tests.

3.) importer.py, MoldenImporter.get_atoms:

if "Angs" in lines[i]:
    angstrom = True
elif "AU" in lines[i]:
    angstrom = False
else:
    msg = "No unit specified in molden Atoms input."
    raise FileFormatError(msg)

The "non-Angström cases" are not covered. Same function:

if "STO" in lines[i]:
    msg = "STO type not implemented."
    raise FileFormatError(msg)

Error raise not covered.

4.) importer_crystal.py, PoscarImporter.parse_poscar:

  if scale_unitcell_to_volume:
      _old_volume = Crystal.calc_volume_unitcell(basis_vectors)
      scale = np.cbrt((-scale) / _old_volume)  # cbrt: cube root

Not covered. Need to create an exemplary input POSCAR for the tests with a negative scale factor.

5.) importer_crystal.py, VasprunImporter.load:

except ImportError as err:
    msg = "pymatgen is not installed, cannot read vasprun.xml files"
    raise FileFormatError(
        msg,
    ) from err

Not covered. Need to find out how this can be covered. Can import of a package be suppressed?