Repository: marrink-lab/vermouth-martinize

Issue:
handle missing dssp error better
there are two options for `-dssp`, either give the path to the installed binary, or just give the flag and hope that mdtraj is installed.

If the latter is done (which it increasingly is in tutorials etc.), but mdtraj is not installed, then the error is not terribly helpful:

```
FileNotFoundError: [Errno 2] No such file or directory: 'dssp'
```

which I think is still assuming the former case (where martinize2 should be looking for an executable). It would be useful to include some indication that possibly the user should install mdtraj as a dependency but this isn't found


Discussion:

Patch:
diff --git a/vermouth/dssp/dssp.py b/vermouth/dssp/dssp.py
index 6491ffa..d0221eb 100644
--- a/vermouth/dssp/dssp.py
+++ b/vermouth/dssp/dssp.py
@@ -271,8 +271,13 @@ def run_dssp(system, executable='dssp', savedir=None, defer_writing=True):
         savefile = _savefile_path(system, savedir)
     else:
         savefile = None
-    # check version
-    process = subprocess.run([executable, "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+
+    try:
+        # check version
+        process = subprocess.run([executable, "--version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    except FileNotFoundError:
+        raise DSSPError("DSSP executable not found. Perhaps MDTraj was not installed in the environment?")
+
     match = re.search('\d+\.\d+\.\d+', process.stdout.decode('UTF8'))
     version = match[0] if match else None
     if not version:


Test patch:
diff --git a/vermouth/tests/test_dssp.py b/vermouth/tests/test_dssp.py
index 28474ff..aa6d393 100644
--- a/vermouth/tests/test_dssp.py
+++ b/vermouth/tests/test_dssp.py
@@ -450,6 +450,16 @@ def test_run_dssp_input_file(tmp_path, caplog, pdb, loglevel, expected):
         # Make sure it's a valid PDB file. Mostly anyway.
         list(read_pdb(matches[0]))
 
+def test_run_dssp_executable():
+    """
+    Test that the executable for dssp is actually found
+    """
+    system = vermouth.System()
+    for molecule in read_pdb(str(PDB_PROTEIN)):
+        system.add_molecule(molecule)
+
+    with pytest.raises(DSSPError):
+        dssp.run_dssp(system, executable='doesnt_exist')
 
 @pytest.mark.parametrize('ss_struct, expected', (
     (list('ABCDE'), list('ABCDE')),