Skip to content

Commit

Permalink
sanitize molecule names for dfhelper (#2984)
Browse files Browse the repository at this point in the history
* Update dfhelper.cc

* Update test_misc.py
  • Loading branch information
loriab committed Jun 17, 2023
1 parent 26ef069 commit 6ebe472
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
4 changes: 3 additions & 1 deletion psi4/src/psi4/lib3index/dfhelper.cc
Expand Up @@ -103,8 +103,10 @@ void DFHelper::AO_filename_maker(size_t i) {

std::string DFHelper::start_filename(std::string start) {
std::string name = PSIOManager::shared_object()->get_default_path();
std::string safe_mol = primary_->molecule()->name();
safe_mol.erase(std::remove(safe_mol.begin(), safe_mol.end(), '/'), safe_mol.end());
name += start + "." + std::to_string(SYSTEM_GETPID());
name += "." + primary_->molecule()->name() + ".";
name += "." + safe_mol + ".";
name += std::to_string(rand()) + "." + ".dat";
return name;
}
Expand Down
10 changes: 10 additions & 0 deletions tests/pytests/test_misc.py
Expand Up @@ -99,6 +99,16 @@ def test_parse_cotton_irreps_error(inp):
assert 'not valid for point group' in str(e.value)


def test_slash_in_molecule_name_plus_dfhelper():
mymol = psi4.core.Molecule.from_arrays(geom=[0, 0, 0, 2, 0, 0], elem=["h", "h"], name="h2/mol")

# segfaults if any DF (that is, following line commented). runs if DF suppressed (following line active)
#psi4.set_options({"scf_type": "pk", "df_basis_guess": "false"})

ene = psi4.energy("b3lyp/cc-pvtz", molecule=mymol)
assert compare_values(-1.00125358, ene, 5, 'weird mol name ok as file')


# <<< TODO Deprecated! Delete in Psi4 v1.5 >>>

@uusing("networkx")
Expand Down

0 comments on commit 6ebe472

Please sign in to comment.