def __init__(self, *filenames): super(AmberParameterSet, self).__init__() self.default_scee = 1.2 self.default_scnb = 2.0 self.titles = [] for filename in filenames: if isinstance(filename, string_types): if AmberOFFLibrary.id_format(filename): self.residues.update(AmberOFFLibrary.parse(filename)) else: self.load_parameters(filename) elif isinstance(filename, Sequence): for fname in filename: if AmberOFFLibrary.id_format(fname): self.residues.update(AmberOFFLibrary.parse(fname)) else: self.load_parameters(fname) else: # Assume open file object self.load_parameters(filename)
def from_leaprc(cls, fname): """ Load a parameter set from a leaprc file Parameters ---------- fname : str or file-like Name of the file or open file-object from which a leaprc-style file will be read Notes ----- This does not read all parts of a leaprc file -- only those pertinent to defining force field information. For instance, the following sections and commands are processed: - addAtomTypes - loadAmberParams - loadOFF """ params = cls() if isinstance(fname, string_types): f = genopen(fname, 'r') own_handle = True else: f = fname own_handle = False # To make parsing easier, and because leaprc files are usually quite # short, I'll read the whole file into memory text = f.read() if own_handle: f.close() lowertext = text.lower() # commands are case-insensitive try: idx = lowertext.index('addatomtypes') except ValueError: # Does not exist in this file atom_types_str = '' else: # Now process the addAtomTypes i = idx + len('addatomtypes') while i < len(text) and text[i] != '{': if text[i] not in '\r\n\t ': raise ParameterError('Unsupported addAtomTypes syntax in ' 'leaprc file') i += 1 if i == len(text): raise ParameterError('Unsupported addAtomTypes syntax in ' 'leaprc file') # We are at our first brace chars = [] nopen = 1 i += 1 while i < len(text): char = text[i] if char == '{': nopen += 1 elif char == '}': nopen -= 1 if nopen == 0: break elif char == '\n': char = ' ' chars.append(char) i += 1 atom_types_str = ''.join(chars).strip() for _, name, symb, hyb in _atomtypere.findall(atom_types_str): if symb not in AtomicNum: raise ParameterError('%s is not a recognized element' % symb) if name in params.atom_types: params.atom_types[name].atomic_number = AtomicNum[symb] else: params.atom_types[name] = \ AtomType(name, len(params.atom_types)+1, Mass[symb], AtomicNum[symb]) # Now process the parameter files for fname in _loadparamsre.findall(text): params.load_parameters(_find_amber_file(fname)) # Now process the library file for fname in _loadoffre.findall(text): params.residues.update( AmberOFFLibrary.parse(_find_amber_file(fname)) ) return params
def from_leaprc(cls, fname, search_oldff=False): """ Load a parameter set from a leaprc file Parameters ---------- fname : str or file-like Name of the file or open file-object from which a leaprc-style file will be read search_oldff : bool, optional, default=False If True, search the oldff directories in the main Amber leap folders. Default is False Notes ----- This does not read all parts of a leaprc file -- only those pertinent to defining force field information. For instance, the following sections and commands are processed: - addAtomTypes - loadAmberParams - loadOFF - loadMol2 - loadMol3 """ params = cls() if isinstance(fname, string_types): f = genopen(fname, 'r') own_handle = True else: f = fname own_handle = False # To make parsing easier, and because leaprc files are usually quite # short, I'll read the whole file into memory def joinlines(lines): newlines = [] composite = [] for line in lines: if line.endswith('\\\n'): composite.append(line[:-2]) continue else: composite.append(line) newlines.append(''.join(composite)) composite = [] if composite: newlines.append(''.join(composite)) return newlines lines = joinlines(map(lambda line: line if '#' not in line else line[:line.index('#')], f)) text = ''.join(lines) if own_handle: f.close() lowertext = text.lower() # commands are case-insensitive # Now process the parameter files def process_fname(fname): if fname[0] in ('"', "'"): fname = fname[1:-1] fname = fname.replace('_BSTOKEN_', r'\ ').replace(r'\ ', ' ') return fname for line in lines: line = line.replace(r'\ ', '_BSTOKEN_') if _loadparamsre.findall(line): fname = process_fname(_loadparamsre.findall(line)[0]) params.load_parameters(_find_amber_file(fname, search_oldff)) elif _loadoffre.findall(line): fname = process_fname(_loadoffre.findall(line)[0]) params.residues.update( AmberOFFLibrary.parse(_find_amber_file(fname, search_oldff)) ) elif _loadmol2re.findall(line): (resname, fname), = _loadmol2re.findall(line) residue = Mol2File.parse(_find_amber_file(fname, search_oldff)) if isinstance(residue, ResidueTemplateContainer): warnings.warn('Multi-residue mol2 files not supported by ' 'tleap. Loading anyway using names in mol2', AmberWarning) for res in residue: params.residues[res.name] = res else: params.residues[resname] = residue # Now process the addAtomTypes try: idx = lowertext.index('addatomtypes') except ValueError: # Does not exist in this file atom_types_str = '' else: i = idx + len('addatomtypes') while i < len(text) and text[i] != '{': if text[i] not in '\r\n\t ': raise ParameterError('Unsupported addAtomTypes syntax in ' 'leaprc file') i += 1 if i == len(text): raise ParameterError('Unsupported addAtomTypes syntax in ' 'leaprc file') # We are at our first brace chars = [] nopen = 1 i += 1 while i < len(text): char = text[i] if char == '{': nopen += 1 elif char == '}': nopen -= 1 if nopen == 0: break elif char == '\n': char = ' ' chars.append(char) i += 1 atom_types_str = ''.join(chars).strip() for _, name, symb, hyb in _atomtypere.findall(atom_types_str): if symb not in AtomicNum: raise ParameterError('%s is not a recognized element' % symb) if name in params.atom_types: params.atom_types[name].atomic_number = AtomicNum[symb] return params
""" Standard residue templates for biomolecular residues """ import os from parmed.amber.offlib import AmberOFFLibrary as _parser StandardBiomolecularResidues = _parser.parse(os.path.join(os.path.split(__file__)[0], "data", "standard_residues.lib"))
""" Standard residue templates for biomolecular residues """ import os from parmed.amber.offlib import AmberOFFLibrary as _parser StandardBiomolecularResidues = _parser.parse( os.path.join(os.path.split(__file__)[0], 'data', 'standard_residues.lib'))