####################################################################### BioSimSpace: Making biomolecular simulation a breeze!## Copyright: 2017-2024## Authors: Lester Hedges <lester.hedges@gmail.com>## BioSimSpace is free software: you can redistribute it and/or modify# it under the terms of the GNU General Public License as published by# the Free Software Foundation, either version 3 of the License, or# (at your option) any later version.## BioSimSpace is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with BioSimSpace. If not, see <http://www.gnu.org/licenses/>.#####################################################################"""Functionality for storing custom simulation protocols.Author: Lester Hedges <lester.hedges@gmail.com>."""__author__="Lester Hedges"__email__="lester.hedges@gmail.com"__all__=["Custom"]importosas_osfrom._protocolimportProtocolas_Protocol
[docs]classCustom(_Protocol):"""A class for storing custom protocols."""
[docs]def__init__(self,config):""" Constructor. Parameters ---------- config : str, [ str ] The custom protocol configuration. """# Call the base class constructor.super().__init__()# Set the protocol configuration.self.setConfig(config)
def__str__(self):"""Return a human readable string representation of the object."""return"<BioSimSpace.Protocol.Custom>"def__repr__(self):"""Return a string showing how to instantiate the object."""return"<BioSimSpace.Protocol.Custom>"def__eq__(self,other):"""Equality operator."""returnself._config==other._config
[docs]defgetConfig(self):""" Return the custom configuration. Returns ------- config : [ str ] Return the list of configuration strings. """returnself._config.copy()
[docs]defsetConfig(self,config):""" Set the custom configuration. Parameters ---------- config : str, [ str ] A config file, or list of configuration strings. """# Check that the passed configuration is a list of strings.if_is_list_of_strings(config):self._config=config# The user has passed a path to a file.elif_os.path.isfile(config):# Clear the existing config.self._config=[]# Read the contents of the file.withopen(config,"r")asfile:forlineinfile:self._config.append(line.rstrip())else:raiseValueError("'config' must be a list of strings, or a file path.")
def_is_list_of_strings(lst):"""Check whether the passed argument is a list of strings."""iflstandisinstance(lst,list):returnall(isinstance(elem,str)foreleminlst)else:returnFalse