def constraint_dct(zma, const_names, var_names=()): """ Build a dictionary of constraints has to round the values for the filesystem """ # Get the list names sorted for dictionary rnames = (name for name in const_names if 'R' in name) anames = (name for name in const_names if 'A' in name) dnames = (name for name in const_names if 'D' in name) rnames = tuple(sorted(rnames, key=lambda x: int(x.split('R')[1]))) anames = tuple(sorted(anames, key=lambda x: int(x.split('A')[1]))) dnames = tuple(sorted(dnames, key=lambda x: int(x.split('D')[1]))) constraint_names = rnames + anames + dnames # Remove the scan coordinates so they are not placed in the dict constraint_names = tuple(name for name in constraint_names if name not in var_names) # Build dictionary if constraint_names: zma_vals = value_dictionary(zma) zma_coords = coordinates(zma) assert set(constraint_names) <= set(zma_coords.keys()), ( 'Attempting to constrain coordinates not in zma:' f'\n{constraint_names}\n{zma_coords}') _dct = dict( zip(constraint_names, (round(zma_vals[name], 2) for name in constraint_names))) else: _dct = None return _dct
def bond_key_from_idxs(zma, idxs): """given indices of involved bonded atoms, return bond name """ idxs = list(idxs) idxs.sort(reverse=True) idxs = tuple(idxs) bond_key = None coords = coordinates(zma) for key in coords: for coord in coords.get(key, [None]): if idxs == coord: bond_key = key return bond_key
def dihedral_axis_name(zma, axis): """ gives this name of a dihedral angle that has the given axis atoms """ coords = coordinates(zma) angles = dihedral_angle_names(zma) name = None for ang in angles: _coord_idxs = coords[ang] if (tuple(list(_coord_idxs[0])[1:3]) == axis or tuple(list(_coord_idxs[0])[3:1:-1]) == axis): name = ang break return name
def set_constraint_names(zma, tors_names, tors_model): """ Determine the names of constraints along a torsion scan """ constraint_models = ('1dhrf', '1dhrfa', 'tau-1dhrf', 'tau-1dhrfa') const_names = tuple() if tors_names and tors_model in constraint_models: if tors_model in ('1dhrf', 'tau-1dhrf'): const_names = tuple(itertools.chain(*tors_names)) elif tors_model in ('1dhrfa', 'tau-1dhrfa'): coords = list(coordinates(zma)) const_names = tuple(coord for coord in coords) return const_names
def dihedral_axis_name(zma, axis): """ gives this name of a dihedral angle that has the given axis atoms currently fails if indices of axis not in zma, i.e. if 5,1 in zma, code fails if 1,5 given """ coords = coordinates(zma) angles = dihedral_angle_names(zma) name = None for ang in angles: _coord_idxs = coords[ang] if (tuple(list(_coord_idxs[0])[1:3]) == axis or tuple(list(_coord_idxs[0])[3:1:-1]) == axis): name = ang break return name
def coord_idxs(zma, key): """give a bond length key, return the indices of involved bonded atoms """ coords = coordinates(zma) idxs = coords.get(key, [None]) return idxs[0]
def coordinates(zma, shift=0, multi=True): """ coordinate keys associated with each coordinate name, as a dictionary """ return vmat.coordinates(vmatrix(zma), shift=shift, multi=multi)