Esempio n. 1
0
 def init_amber(self, params, pdb_hierarchy, log):
     if hasattr(params, "amber"):
         self.use_amber = params.amber.use_amber
         print_amber_energies = params.amber.print_amber_energies
         if (self.use_amber):
             sites_cart = pdb_hierarchy.atoms().extract_xyz()
             compute_gradients = False
             make_header("Initializing AMBER", out=log)
             print >> log, "  topology    : %s" % params.amber.topology_file_name
             print >> log, "  atom order  : %s" % params.amber.order_file_name
             if params.amber.coordinate_file_name:
                 print >> log, "  coordinates : %s" % params.amber.coordinate_file_name
             from amber_adaptbx import interface
             self.amber_structs, sander = interface.get_amber_struct_object(
                 params)
             self.sander = sander  # used for cleanup
             import amber_adaptbx
             amber_geometry_manager = amber_adaptbx.geometry_manager(
                 sites_cart=sites_cart,
                 #number_of_restraints=geometry_energy.number_of_restraints,
                 gradients_factory=flex.vec3_double,
                 amber_structs=self.amber_structs)
             geometry = amber_geometry_manager.energies_sites(
                 crystal_symmetry=self.geometry.crystal_symmetry,
                 compute_gradients=compute_gradients)
 def show(self, amber_structs, log=None):
   import amber_adaptbx as amber
   amber_geometry_manager=amber.geometry_manager(
      sites_cart=self.pdb_hierarchy.atoms().extract_xyz(),
      amber_structs=amber_structs)
   amber_geometry=amber_geometry_manager.energies_sites(
      self.restraints_manager.geometry.crystal_symmetry,
      log=log,
      )
   amber_geometry.show()
Esempio n. 3
0
    def energies_sites(
        self,
        sites_cart,
        geometry_flags=None,
        external_energy_function=None,
        custom_nonbonded_function=None,
        compute_gradients=False,
        gradients=None,
        force_restraints_model=False,
        disable_asu_cache=False,
        hd_selection=None,
    ):
        """
    Compute energies for coordinates.  Originally this just used the standard
    geometry restraints from the monomer library, but it has since been
    extended to optionally incorporate a variety of external energy functions.

    :returns: scitbx.restraints.energies object
    """
        result = scitbx.restraints.energies(
            compute_gradients=compute_gradients,
            gradients=gradients,
            gradients_size=sites_cart.size(),
            gradients_factory=flex.vec3_double,
            normalization=self.normalization)
        if (self.geometry is None):
            result.geometry = None
        else:
            if (self.use_amber and not force_restraints_model):
                geometry_energy = self.geometry.energies_sites(
                    sites_cart=sites_cart,
                    flags=geometry_flags,
                    external_energy_function=external_energy_function,
                    custom_nonbonded_function=custom_nonbonded_function,
                    compute_gradients=False,
                    gradients=None,
                    disable_asu_cache=disable_asu_cache,
                    normalization=False)
                ##################################################################
                #                                                                #
                # AMBER CALL - Amber force field gradients and target            #
                #                                                                #
                ##################################################################
                import amber_adaptbx
                amber_geometry_manager = amber_adaptbx.geometry_manager(
                    sites_cart=sites_cart,
                    number_of_restraints=geometry_energy.number_of_restraints,
                    gradients_factory=flex.vec3_double,
                    amber_structs=self.amber_structs)
                result.geometry = amber_geometry_manager.energies_sites(
                    crystal_symmetry=self.geometry.crystal_symmetry,
                    compute_gradients=compute_gradients)

            elif (self.use_afitt
                  and len(sites_cart) == self.afitt_object.total_model_atoms):
                ##################################################################
                #                                                                #
                # AFITT CALL - OpenEye AFITT gradients and target                #
                #                                                                #
                ##################################################################
                from mmtbx.geometry_restraints import afitt
                result.geometry = self.geometry.energies_sites(
                    sites_cart=sites_cart,
                    flags=geometry_flags,
                    external_energy_function=external_energy_function,
                    custom_nonbonded_function=custom_nonbonded_function,
                    compute_gradients=compute_gradients,
                    gradients=result.gradients,
                    disable_asu_cache=disable_asu_cache,
                    normalization=False,
                )
                result = afitt.apply(result, self.afitt_object, sites_cart)
                result = afitt.adjust_energy_and_gradients(
                    result,
                    self,
                    sites_cart,
                    hd_selection,
                    self.afitt_object,
                )
                result.target = result.residual_sum
                result.afitt_energy = result.residual_sum
            else:
                result.geometry = self.geometry.energies_sites(
                    sites_cart=sites_cart,
                    flags=geometry_flags,
                    external_energy_function=external_energy_function,
                    custom_nonbonded_function=custom_nonbonded_function,
                    compute_gradients=compute_gradients,
                    gradients=result.gradients,
                    disable_asu_cache=disable_asu_cache,
                    normalization=False)
            result += result.geometry
        if (self.cartesian_ncs_manager is None):
            result.cartesian_ncs_manager = None
        else:
            result.cartesian_ncs_manager = self.cartesian_ncs_manager.energies_sites(
                sites_cart=sites_cart,
                compute_gradients=compute_gradients,
                gradients=result.gradients,
                normalization=False)
            result += result.cartesian_ncs_manager
        result.finalize_target_and_gradients()
        return result
Esempio n. 4
0
  def energies_sites(self,
        sites_cart,
        geometry_flags=None,
        external_energy_function=None,
        custom_nonbonded_function=None,
        compute_gradients=False,
        gradients=None,
        force_restraints_model=False,
        disable_asu_cache=False,
        hd_selection=None,
        ):
    """
    Compute energies for coordinates.  Originally this just used the standard
    geometry restraints from the monomer library, but it has since been
    extended to optionally incorporate a variety of external energy functions.

    :returns: scitbx.restraints.energies object
    """
    result = scitbx.restraints.energies(
      compute_gradients=compute_gradients,
      gradients=gradients,
      gradients_size=sites_cart.size(),
      gradients_factory=flex.vec3_double,
      normalization=self.normalization)
    if (self.geometry is None):
      result.geometry = None
    else:
      if (self.use_amber and not force_restraints_model) :
        geometry_energy = self.geometry.energies_sites(
          sites_cart=sites_cart,
          flags=geometry_flags,
          external_energy_function=external_energy_function,
          custom_nonbonded_function=custom_nonbonded_function,
          compute_gradients=False,
          gradients=None,
          disable_asu_cache=disable_asu_cache,
          normalization=False)
        ##################################################################
        #                                                                #
        # AMBER CALL - Amber force field gradients and target            #
        #                                                                #
        ##################################################################
        import amber_adaptbx
        amber_geometry_manager = amber_adaptbx.geometry_manager(
          sites_cart=sites_cart,
          number_of_restraints=geometry_energy.number_of_restraints,
          gradients_factory=flex.vec3_double,
          amber_structs=self.amber_structs)
        result.geometry = amber_geometry_manager.energies_sites(
          crystal_symmetry = self.geometry.crystal_symmetry,
          compute_gradients = compute_gradients)

      elif (self.use_afitt and
            len(sites_cart)==self.afitt_object.total_model_atoms
            ):
        ##################################################################
        #                                                                #
        # AFITT CALL - OpenEye AFITT gradients and target                #
        #                                                                #
        ##################################################################
        from mmtbx.geometry_restraints import afitt
        result.geometry = self.geometry.energies_sites(
          sites_cart=sites_cart,
          flags=geometry_flags,
          external_energy_function=external_energy_function,
          custom_nonbonded_function=custom_nonbonded_function,
          compute_gradients=compute_gradients,
          gradients=result.gradients,
          disable_asu_cache=disable_asu_cache,
          normalization=False,
          )
        result = afitt.apply(result, self.afitt_object, sites_cart)
        result = afitt.adjust_energy_and_gradients(
          result,
          self,
          sites_cart,
          hd_selection,
          self.afitt_object,
        )
        result.target = result.residual_sum
        result.afitt_energy=result.residual_sum
      else :
        result.geometry = self.geometry.energies_sites(
          sites_cart=sites_cart,
          flags=geometry_flags,
          external_energy_function=external_energy_function,
          custom_nonbonded_function=custom_nonbonded_function,
          compute_gradients=compute_gradients,
          gradients=result.gradients,
          disable_asu_cache=disable_asu_cache,
          normalization=False)
      result += result.geometry
    if (self.ncs_groups is None):
      result.ncs_groups = None
    else:
      result.ncs_groups = self.ncs_groups.energies_sites(
        sites_cart=sites_cart,
        compute_gradients=compute_gradients,
        gradients=result.gradients,
        normalization=False)
      result += result.ncs_groups
    result.finalize_target_and_gradients()
    return result