def _parse_params_values(parent_tag, units_dict, child_tag, expression=None): # Tag of type Parameters can exist atmost once params_dict = {} if parent_tag.find('Parameters') is None: return params_dict for param in parent_tag.find('Parameters').getiterator('Parameter'): if param.attrib['name'] not in units_dict: raise ForceFieldParseError( 'Parameters {} with Unknown units found'.format( param.attrib['name'])) param_name = param.attrib['name'] param_unit = units_dict[param_name] param_value = u.unyt_quantity(float(param.attrib['value']), param_unit) params_dict[param_name] = param_value param_ref_dict = units_dict if child_tag == 'DihedralType': if not expression: raise ForceFieldError( 'Cannot consolidate parameters without an expression') _consolidate_params(params_dict, expression) param_ref_dict = _consolidate_params(units_dict, expression, update_orig=False) for param in param_ref_dict: if param not in params_dict: raise ForceFieldParseError( 'Parameter {} is in units but cannot be found in parameters list' .format(param)) return params_dict
def _parse_params_values(parent_tag, units_dict, child_tag, expression=None): """Return the values of the parameters.""" # Tag of type Parameters can exist atmost once params_dict = {} if parent_tag.find("Parameters") is None: return params_dict for param in parent_tag.find("Parameters").getiterator("Parameter"): if param.attrib["name"] not in units_dict: raise ForceFieldParseError( "Parameters {} with Unknown units found".format( param.attrib["name"])) param_name = param.attrib["name"] param_unit = units_dict[param_name] param_value = u.unyt_quantity(float(param.attrib["value"]), param_unit) params_dict[param_name] = param_value param_ref_dict = units_dict if child_tag == "DihedralType": if not expression: raise ForceFieldError( "Cannot consolidate parameters without an expression") _consolidate_params(params_dict, expression) param_ref_dict = _consolidate_params(units_dict, expression, update_orig=False) for param in param_ref_dict: if param not in params_dict: raise ForceFieldParseError( "Parameter {} is in units but cannot be found in parameters list" .format(param)) return params_dict
def _check_valid_atomtype_names(tag, ref_dict): at1 = tag.attrib.get('type1', None) at2 = tag.attrib.get('type2', None) at3 = tag.attrib.get('type3', None) at4 = tag.attrib.get('type4', None) member_types = list(filter(lambda x: x is not None, [at1, at2, at3, at4])) member_types = ['*' if mem_type == '' else mem_type for mem_type in member_types] for member in member_types: if member == '*': continue if member not in ref_dict: raise ForceFieldParseError('AtomTypes {} not present in AtomTypes reference in the xml'.format(member)) return member_types
def _check_atomtype_existence(tag, ref_dict): at1 = tag.attrib.get('type1', tag.attrib.get('class1', None)) at2 = tag.attrib.get('type2', tag.attrib.get('class2', None)) at3 = tag.attrib.get('type3', tag.attrib.get('class3', None)) at4 = tag.attrib.get('type4', tag.attrib.get('class4', None)) atom_classes_set = set(value.atomclass for value in ref_dict.values() if value) member_types = list(filter(lambda x: x is not None, [at1, at2, at3, at4])) member_types = [ '*' if mem_type == '' else mem_type for mem_type in member_types ] for member in member_types: if member == '*': continue if member not in ref_dict and member not in atom_classes_set: raise ForceFieldParseError( 'AtomType/AtomClass {} not present in AtomTypes reference in the xml' .format(member)) return member_types