def test_xmls(ff_file): file_name = os.path.split(ff_file)[1] if 'error' in file_name: error_type = ERRORS[file_name.split('_')[0]] with pytest.raises(error_type): Validator(ff_file) elif file_name.startswith('warning'): with pytest.warns(ValidationWarning): Validator(ff_file) else: Validator(ff_file)
def test_xmls(self, ff_file): file_name = os.path.split(ff_file)[1] if "error" in file_name: error_type = ERRORS[file_name.split("_")[0]] with pytest.raises(error_type): Validator(ff_file) elif file_name.startswith("warning"): with pytest.warns(ValidationWarning): Validator(ff_file) else: Validator(ff_file)
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._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) preprocessed_files = preprocess_forcefield_files(all_files_to_load) if validation: for ff_file_name in preprocessed_files: Validator(ff_file_name, debug) super(Forcefield, self).__init__(*preprocessed_files) self.parser = smarts.SMARTS(self.non_element_types)
def preprocess_forcefield_files(forcefield_files=None, backend="gmso"): """Pre-process foyer Forcefield XML files.""" if forcefield_files is None: return None tmp_processed_files = list() if backend == "gmso": # Run through the forcefield XML conversion from gmso.external.convert_foyer_xml import from_foyer_xml for idx, file in enumerate(forcefield_files): _, suffix = os.path.split(file) tempfile = NamedTemporaryFile(suffix=suffix, delete=False) try: Validator(ff_file_name=file, debug=False) from_foyer_xml( foyer_xml=str(file), gmso_xml=str(tempfile.name), overwrite=True, ) except: warnings.warn(f"Could not convert {str(file)} as a foyer XML," f"attempt to read in as a GMSO XML.") shutil.copyfile(file, tempfile.name) tmp_processed_files.append(tempfile.name) else: raise FoyerError("Backend not supported." 'Supports backend: "gmso".') return tmp_processed_files
def _validate_foyer(xml_path): import warnings from gmso.utils.io import has_foyer if not has_foyer: warnings.warn( 'Cannot validate the xml using foyer, since foyer is not installed.' 'Please install foyer using conda install -c conda-forge foyer.' ) else: from foyer.validator import Validator Validator(xml_path)
def test_forcefields(ff_file): Validator(ff_file)