def target_and_gradients(self, unit_cell, sites_cart, gradient_array=None): if (gradient_array is None): gradient_array = flex.vec3_double(sites_cart.size(), (0.0, 0.0, 0.0)) overall_residual_sum = 0 # Oldfield self.residuals_array_oldfield = None #residuals_array_oldfield n_oldfield_proxies = self.get_n_oldfield_proxies() oldfield_residual_sum = 0 if n_oldfield_proxies > 0: if self.residuals_array_oldfield is None: self.residuals_array_oldfield = flex.double( n_oldfield_proxies, 0.) op = self.params.oldfield w = op.weight if w is None: w = 0. oldfield_residual_sum = ramachandran_residual_sum( sites_cart=sites_cart, proxies=self._oldfield_proxies, gradient_array=gradient_array, phi_psi_targets=self.target_phi_psi, weights=(w, op.weight_scale, op.distance_weight_min, op.distance_weight_max), residuals_array=self.residuals_array_oldfield) overall_residual_sum += oldfield_residual_sum # Emsley self.residuals_array_emsley = None #residuals_array_emsley n_emsley_proxies = self.get_n_emsley_proxies() if n_emsley_proxies > 0: if self.residuals_array_emsley is None: self.residuals_array_emsley = flex.double(n_emsley_proxies, 0.) #assert (self.params.rama_weight >= 0.0) # Moving these cycles to C++ part would speed them up only up to 10% for i, proxy in enumerate(self._emsley_proxies): rama_table = self._emsley_tables[self.new_to_old_conversion[ proxy.residue_type]] self.residuals_array_emsley[i] = rama_table.compute_gradients( gradient_array=gradient_array, sites_cart=sites_cart, proxy=proxy, epsilon=0.001) overall_residual_sum += flex.sum(self.residuals_array_emsley) # emsley8k self.residuals_array_emsley8k = None n_emsley8k_proxies = self.get_n_emsley8k_proxies() if n_emsley8k_proxies > 0: if self.residuals_array_emsley8k is None: self.residuals_array_emsley8k = flex.double( n_emsley8k_proxies, 0.) for i, proxy in enumerate(self._emsley8k_proxies): rama_table = self._emsley8k_tables[proxy.residue_type] self.residuals_array_emsley8k[ i] = rama_table.compute_gradients( gradient_array=gradient_array, sites_cart=sites_cart, proxy=proxy, epsilon=1.0) # XXX overall_residual_sum += flex.sum(self.residuals_array_emsley8k) return overall_residual_sum
def target_and_gradients(self, unit_cell, sites_cart, gradient_array=None, residuals_array=None): assert self.proxies is not None if (gradient_array is None): gradient_array = flex.vec3_double(sites_cart.size(), (0.0, 0.0, 0.0)) if residuals_array is None: residuals_array = flex.double(self.proxies.size()) target = 0 if (self.params.rama_potential == "oldfield"): op = self.params.oldfield w = op.weight if w is None: w = -1 res = ramachandran_residual_sum( sites_cart=sites_cart, proxies=self.proxies, gradient_array=gradient_array, phi_psi_targets=self.target_phi_psi, weights=(w, op.esd, op.dist_weight_max, 2.0, op.weight_scale), residuals_array=residuals_array) return res else: # emsley assert (self.params.rama_weight >= 0.0) # bad hack to keep emsley potential in working(?) condition after # changing from rama500 to rama8000 new_to_old_conversion = { "general": "ala", "glycine": "gly", "cis-proline": "pro", "trans-proline": "pro", "pre-proline": "prepro", "isoleucine or valine": "ala" } # Moving these cycles to C++ part would speed them up only up to 10% for i, proxy in enumerate(self.proxies): rama_table = self.tables[new_to_old_conversion[ proxy.residue_type]] residuals_array[i] = rama_table.compute_gradients( gradient_array=gradient_array, sites_cart=sites_cart, proxy=proxy, weight=self.params.rama_weight, epsilon=0.001) return flex.sum(residuals_array)
def target_and_gradients (self, unit_cell, sites_cart, gradient_array=None, residuals_array=None) : assert self.proxies is not None if(gradient_array is None) : gradient_array = flex.vec3_double(sites_cart.size(), (0.0,0.0,0.0)) if residuals_array is None: residuals_array = flex.double(self.proxies.size()) target = 0 if(self.params.rama_potential == "oldfield"): op = self.params.oldfield w = op.weight if w is None: w = -1 res = ramachandran_residual_sum( sites_cart=sites_cart, proxies=self.proxies, gradient_array=gradient_array, general_table=self.tables.general, gly_table=self.tables.gly, cispro_table=self.tables.cispro, transpro_table=self.tables.transpro, prepro_table=self.tables.prepro, ileval_table=self.tables.ileval, weights=(w, op.esd, op.dist_weight_max, 2.0, op.weight_scale), residuals_array=residuals_array) return res else: # emsley assert (self.params.rama_weight >= 0.0) # bad hack to keep emsley potential in working(?) condition after # changing from rama500 to rama8000 new_to_old_conversion = {"general":"ala", "glycine":"gly", "cis-proline":"pro", "trans-proline":"pro", "pre-proline":"prepro", "isoleucine or valine":"ala"} # Moving these cycles to C++ part would speed them up only up to 10% for i, proxy in enumerate(self.proxies): rama_table = self.tables[new_to_old_conversion[proxy.residue_type]] residuals_array[i] = rama_table.compute_gradients( gradient_array=gradient_array, sites_cart=sites_cart, proxy=proxy, weight=self.params.rama_weight, epsilon=0.001) return flex.sum(residuals_array)