示例#1
0
    def set_parameters(self, params):
        """Sets the numeric values of all parameters.

        Equivalent to :meth:`~pysic.interactions.bondorder.BondOrderParameters.set_parameter_values`.

        Parameters:
        
        params: list of doubles
            list of values to be assigned to parameters
        """
        if self.accepts_parameters(params):
            self.parameters = params
        else:
            new_params = [[], []]
            if len(params) == self.n_params[0] + self.n_params[1]:
                new_params[0] = params[0:self.n_params[0]]
                new_params[1] = params[self.n_params[0]:self.n_params[1]]

            if self.accepts_parameters(new_params):
                warn("Using parameters \n"+str(new_params)+\
                    "\ninstead of \n"+str(params),3)
                self.parameters = new_params
            else:
                raise InvalidParametersError(
                    'The bond order factor "{bof}" requires {num} parameters.'.
                    format(bof=self.bond_order_type, num=str(self.n_params)))
示例#2
0
    def set_parameters(self, params):
        """Sets the numeric values of all parameters.

        Equivalent to :meth:`~pysic.interactions.bondorder.BondOrderParameters.set_parameter_values`.

        Parameters:
        
        params: list of doubles
            list of values to be assigned to parameters
        """
        if self.accepts_parameters(params):
            self.parameters = params
        else:
            new_params = [[], []]
            if len(params) == self.n_params[0] + self.n_params[1]:
                new_params[0] = params[0 : self.n_params[0]]
                new_params[1] = params[self.n_params[0] : self.n_params[1]]

            if self.accepts_parameters(new_params):
                warn("Using parameters \n" + str(new_params) + "\ninstead of \n" + str(params), 3)
                self.parameters = new_params
            else:
                raise InvalidParametersError(
                    'The bond order factor "{bof}" requires {num} parameters.'.format(
                        bof=self.bond_order_type, num=str(self.n_params)
                    )
                )
示例#3
0
 def get_pseudo_density(self):
     """Returns the electron pseudo density if available.
     """
     if self.pseudo_density is not None:
         return copy.copy(self.pseudo_density)
     else:
         if hasattr(self.calculator, "get_pseudo_density"):
             return copy.copy(self.calculator.get_pseudo_density(self.atoms_for_subsystem))
         else:
             warn("The pseudo density for subsystem \"" + self.name + "\" is not available.", 2)
示例#4
0
 def get_pseudo_density(self):
     """Returns the electron pseudo density if available.
     """
     if self.pseudo_density is not None:
         return copy.copy(self.pseudo_density)
     else:
         if hasattr(self.calculator, "get_pseudo_density"):
             return copy.copy(
                 self.calculator.get_pseudo_density(
                     self.atoms_for_subsystem))
         else:
             warn(
                 "The pseudo density for subsystem \"" + self.name +
                 "\" is not available.", 2)
示例#5
0
    def enable_charge_calculation(self,
                                  division="Bader",
                                  source="all-electron",
                                  gridrefinement=4):
        """Enable the dynamic calculation of atom-centered charges with the
        specified algorithm and from the specified electron density. These
        charges are only used for the interaction between other subsystems.

        Parameters:
            division: string
                Indicates the division algorithm that is used. Available options are:
                    
                    - "Bader": Bader algorithm
                    - "van Der Waals": Spheres with van Der Waals radius

            source: string
                Indicates what type of electron density is used. Available
                options are:
                
                    - "pseudo": Use the pseudo electron density provided by all ASE DFT calculators
                    - "all-electron": Use the all-electron density provided by at least GPAW

            gridrefinement: int
                Indicates the subdivision that is used for the all-electron
                density.  Can be other than unity only for Bader algorithm with
                all-electron density.
        """
        divisions = ["Bader", "van Der Waals"]
        charge_sources = ["pseudo", "all-electron"]

        if division not in divisions:
            error("Invalid division algorithm: " + division)

        if source not in charge_sources:
            error("Invalid source for electron density: " + source)

        if gridrefinement != 1:
            if (division != "Bader") or (division == "Bader"
                                         and source != "all-electron"):
                warn(
                    "The gridrefinement is available only for the Bader algorithm with all-electron density, it is ignored.",
                    3)

        self.charge_calculation_enabled = True
        self.division = division
        self.charge_source = source
        self.gridrefinement = gridrefinement
示例#6
0
    def enable_charge_calculation(self, division="Bader", source="all-electron", gridrefinement=4):
        """Enable the dynamic calculation of atom-centered charges with the
        specified algorithm and from the specified electron density. These
        charges are only used for the interaction between other subsystems.

        Parameters:
            division: string
                Indicates the division algorithm that is used. Available options are:
                    
                    - "Bader": Bader algorithm
                    - "van Der Waals": Spheres with van Der Waals radius

            source: string
                Indicates what type of electron density is used. Available
                options are:
                
                    - "pseudo": Use the pseudo electron density provided by all ASE DFT calculators
                    - "all-electron": Use the all-electron density provided by at least GPAW

            gridrefinement: int
                Indicates the subdivision that is used for the all-electron
                density.  Can be other than unity only for Bader algorithm with
                all-electron density.
        """
        divisions = ["Bader", "van Der Waals"]
        charge_sources = ["pseudo", "all-electron"]

        if division not in divisions:
            error("Invalid division algorithm: " + division)

        if source not in charge_sources:
            error("Invalid source for electron density: " + source)

        if gridrefinement != 1:
            if (division != "Bader") or (division == "Bader" and source != "all-electron"):
                warn("The gridrefinement is available only for the Bader algorithm with all-electron density, it is ignored.", 3)

        self.charge_calculation_enabled = True
        self.division = division
        self.charge_source = source
        self.gridrefinement = gridrefinement
示例#7
0
    def __init__(self, atoms, info, index_map, reverse_index_map, n_atoms):
        """
        Parameters:
            atoms: ASE Atoms
                The subsystem atoms.
            info: SubSystem object
                Contains all the information about the subsystem
            index_map: dictionary of int to int
                The keys are the atom indices in the full system, values are
                indices in the subssystem.
            reverse_index_map: dicitonary of int to int
                The keys are the atom indices in the subsystem, values are the
                keys in the full system.
            n_atoms: int
                Number of atoms in the full system.
        """
        # Extract data from info
        self.name = info.name
        self.calculator = copy.copy(info.calculator)
        self.cell_size_optimization_enabled = info.cell_size_optimization_enabled
        self.cell_padding = info.cell_padding
        self.charge_calculation_enabled = info.charge_calculation_enabled
        self.charge_source = info.charge_source
        self.division = info.division
        self.gridrefinement = info.gridrefinement

        self.n_atoms = n_atoms
        self.atoms_for_interaction = atoms.copy()
        self.atoms_for_subsystem = atoms.copy()
        self.index_map = index_map
        self.reverse_index_map = reverse_index_map
        self.potential_energy = None
        self.forces = None
        self.density_grid = None
        self.pseudo_density = None
        self.link_atom_indices = []
        self.timer = Timer([
            "Bader charge calculation", "van Der Waals charge calculation",
            "Energy", "Forces", "Density grid update", "Cell minimization"
        ])

        # The older ASE versions do not support get_initial_charges()
        try:
            charges = np.array(atoms.get_initial_charges())
        except:
            charges = np.array(atoms.get_charges())
        self.initial_charges = charges

        ## Can't enable charge calculation on non-DFT calculator
        self.dft_system = hasattr(self.calculator, "get_pseudo_density")
        if self.charge_calculation_enabled is True and not self.dft_system:
            error("Can't enable charge calculation on non-DFT calculator!")

        # If the cell size minimization flag has been enabled, then try to reduce the
        # cell size
        if self.cell_size_optimization_enabled:
            pbc = atoms.get_pbc()
            if pbc[0] or pbc[1] or pbc[2]:
                warn(("Cannot optimize cell size when periodic boundary"
                      "condition have been enabled, disabling optimization."),
                     2)
                self.cell_size_optimization_enabled = False
            else:
                self.optimize_cell()
示例#8
0
    def __init__(self, atoms, info, index_map, reverse_index_map, n_atoms):
        """
        Parameters:
            atoms: ASE Atoms
                The subsystem atoms.
            info: SubSystem object
                Contains all the information about the subsystem
            index_map: dictionary of int to int
                The keys are the atom indices in the full system, values are
                indices in the subssystem.
            reverse_index_map: dicitonary of int to int
                The keys are the atom indices in the subsystem, values are the
                keys in the full system.
            n_atoms: int
                Number of atoms in the full system.
        """
        # Extract data from info
        self.name = info.name
        self.calculator = copy.copy(info.calculator)
        self.cell_size_optimization_enabled = info.cell_size_optimization_enabled
        self.cell_padding = info.cell_padding
        self.charge_calculation_enabled = info.charge_calculation_enabled
        self.charge_source = info.charge_source
        self.division = info.division
        self.gridrefinement = info.gridrefinement

        self.n_atoms = n_atoms
        self.atoms_for_interaction = atoms.copy()
        self.atoms_for_subsystem = atoms.copy()
        self.index_map = index_map
        self.reverse_index_map = reverse_index_map
        self.potential_energy = None
        self.forces = None
        self.density_grid = None
        self.pseudo_density = None
        self.link_atom_indices = []
        self.timer = Timer([
            "Bader charge calculation",
            "van Der Waals charge calculation",
            "Energy",
            "Forces",
            "Density grid update",
            "Cell minimization"])

        # The older ASE versions do not support get_initial_charges()
        try:
            charges = np.array(atoms.get_initial_charges())
        except:
            charges = np.array(atoms.get_charges())
        self.initial_charges = charges

        ## Can't enable charge calculation on non-DFT calculator
        self.dft_system = hasattr(self.calculator, "get_pseudo_density")
        if self.charge_calculation_enabled is True and not self.dft_system:
            error("Can't enable charge calculation on non-DFT calculator!")

        # If the cell size minimization flag has been enabled, then try to reduce the
        # cell size
        if self.cell_size_optimization_enabled:
            pbc = atoms.get_pbc()
            if pbc[0] or pbc[1] or pbc[2]:
                warn(("Cannot optimize cell size when periodic boundary"
                      "condition have been enabled, disabling optimization."), 2)
                self.cell_size_optimization_enabled = False
            else:
                self.optimize_cell()