From 5140b74b0c4492a1299935fd062ecd07aa957303 Mon Sep 17 00:00:00 2001 From: Alexander Moriarty Date: Wed, 30 Aug 2023 18:05:25 +0100 Subject: [PATCH] Fix top file suffix after changing from template --- mdpow/equil.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/mdpow/equil.py b/mdpow/equil.py index 6a18de9c..92d4de5b 100644 --- a/mdpow/equil.py +++ b/mdpow/equil.py @@ -33,6 +33,7 @@ import os, errno import shutil +from pathlib import Path from string import Template from typing import Optional @@ -371,7 +372,18 @@ def topology(self, itp="drug.itp", prm=None, **kwargs): template = forcefields.get_top_template(self.solvent_type) top_template = config.get_template(kwargs.pop("top_template", template)) - topol = kwargs.pop("topol", os.path.basename(top_template)) + + default_top_path = Path(top_template) + if ".top" in default_top_path.suffixes: + # Include all suffixes up to that one + default_top_name = default_top_path.name + default_top_name = ( + default_top_name[: default_top_name.index(".top")] + ".top" + ) + else: + default_top_name = default_top_path.with_suffix(".top").name + + topol = kwargs.pop("topol", default_top_name) self.top_template = top_template itp = os.path.realpath(itp) _itp = os.path.basename(itp)