def __init__(self, forcefield_files=None, name=None): self.atomTypeDefinitions = dict() self.atomTypeOverrides = dict() self.atomTypeDesc = dict() self.atomTypeRefs = dict() self._included_forcefields = dict() self.non_element_types = dict() all_files_to_load = [] if forcefield_files is not None: if isinstance(forcefield_files, (list, tuple, set)): for file in forcefield_files: all_files_to_load.append(file) else: all_files_to_load.append(forcefield_files) if name is not None: try: file = self.included_forcefields[name] except KeyError: raise IOError('Forcefield {} cannot be found'.format(name)) else: all_files_to_load.append(file) super(Forcefield, self).__init__(*all_files_to_load) self.parser = smarts.SMARTS(self.non_element_types)
def __init__(self, forcefield_files=None, name=None, validation=True, debug=False): self.atomTypeDefinitions = dict() self.atomTypeOverrides = dict() self.atomTypeDesc = dict() self.atomTypeRefs = dict() self.atomTypeClasses = dict() self.atomTypeElements = dict() self._included_forcefields = dict() self.non_element_types = dict() self._version = None self._name = None all_files_to_load = [] if forcefield_files is not None: if isinstance(forcefield_files, (list, tuple, set)): for file in forcefield_files: all_files_to_load.append(file) else: all_files_to_load.append(forcefield_files) if name is not None: try: file = self.included_forcefields[name] except KeyError: raise IOError('Forcefield {} cannot be found'.format(name)) else: all_files_to_load.append(file) preprocessed_files = preprocess_forcefield_files(all_files_to_load) if validation: for ff_file_name in preprocessed_files: Validator(ff_file_name, debug) try: super(Forcefield, self).__init__(*preprocessed_files) finally: for ff_file_name in preprocessed_files: os.remove(ff_file_name) if isinstance(forcefield_files, str): self._version = self._parse_version_number(forcefield_files) self._name = self._parse_name(forcefield_files) elif isinstance(forcefield_files, list): self._version = [ self._parse_version_number(f) for f in forcefield_files ] self._name = [self._parse_name(f) for f in forcefield_files] self.parser = smarts.SMARTS(self.non_element_types) self._SystemData = self._SystemData()
def __init__(self, forcefield_files=None, name=None, backend="gmso", **kwargs): self.atomTypeDefinitions = dict() self.atomTypeOverrides = dict() self.atomTypeDesc = dict() self.atomTypeRefs = dict() self.atomTypeClasses = dict() self.atomTypeElements = dict() self._included_forcefields = dict() self.backend = backend self.non_element_types = dict() self._version = None self._name = None all_files_to_load = [] if forcefield_files is not None: if isinstance(forcefield_files, (list, tuple, set)): all_files_to_load = list(forcefield_files) else: all_files_to_load = [forcefield_files] if name is not None: try: file = self.included_forcefields[name] except KeyError: raise IOError("Forcefield {} cannot be found.".format(name)) else: all_files_to_load = [file] # Preprocessed the input files preprocessed_files = preprocess_forcefield_files(all_files_to_load, backend=backend) # Load in an internal forcefield object depends on given backend if backend == "gmso": self._parse_gmso(preprocessed_files, **kwargs) else: raise FoyerError("Backend not supported." 'Supoprts backend: "gmso".') # Remove the temporary files afterward for ff_file_name in preprocessed_files: os.remove(ff_file_name) self.parser = smarts.SMARTS(self.non_element_types)