Пример #1
0
    def pack(self, params, with_indices=False):
        '''
        Packs the parameters object from a 1D array.  NOTE! This is done in
        primarily for parameterization; which means the 1D array will NOT have
        the indices in it.  This can be overridden, however, by specifying the
        with_indices flag.

        Keep in mind, to maintain symmetry requirements in tersoff (where
        the two-body parameters are the same between A-B B and B-A A), this
        function will be tied closely to the unpack function.

        **Parameters**

            params: *list, float/int*
                A list of parameters
            with_indices: *bool, optional*
                Whether to account for the indices in the flat array.

        **Returns**

            None

        '''
        param_types, _ = self._get_param_list(trim_tersoff_2body=True)
        offset = 0
        for param_type in param_types:
            for p in param_type:
                if ffh.check_restriction(p, self.restrict):
                    p.pack(params[offset:offset + p.N_params +
                                  int(with_indices)])
                offset += p.N_params + int(with_indices)

        #self.tersoff_params = sorted_force_2body_symmetry(self.tersoff_params)
        sorted_force_2body_symmetry(self.tersoff_params)
Пример #2
0
    def dump_dihedrals(self):
        '''
        Get a string for lammps input in regards to assigning dihedral coeffs.

        **Returns**

            coeffs: *str*
                A string of dihedral coeffs, with new line characters between
                different dihedrals.
        '''

        lammps_command = []
        if self.opls_structure_dict is None:
            restrict_structures = None
        else:
            restrict_structures = [
                v for k, v in self.opls_structure_dict.items()
                if k in self.restrict
            ]

        # Loop through all possible dihedral parameters
        index = 1
        for dihedral in self.dihedral_params:
            # Skip those that are not included
            if not ffh.check_restriction(dihedral, restrict_structures):
                continue
            # Get the dihedral coeff string
            lammps_command.append(
                "dihedral_coeff %d %s" %
                (index, dihedral.printer(map_indices=self.mapper)))
            index += 1

        return "\n".join(lammps_command)
Пример #3
0
    def write_smrff(self, fname):
        '''
        A function to save a SMRFF parameter file.

        **Parameters**

            fname: *str*
                The file name to save the parameters to.

        **Returns**

            None
        '''

        params = ""
        param_types, param_string_identifiers = self._get_param_list()
        for param_type, param_string in zip(param_types,
                                            param_string_identifiers):
            if param_type is not None:
                params = params.strip() + "\n" + param_string + "\n"
                params += "\n".join([
                    str(p) for p in param_type
                    if ffh.check_restriction(p, self.restrict)
                ])
                params += "\nEND"
        params = params.strip()

        fptr = open(fname, 'w')
        fptr.write(params)
        fptr.close()
Пример #4
0
    def dump_set_charge(self):
        '''
        This function will get the lammps command line argument for
        "set type" of everything within the Parameters object.

        **Parameters**

            None

        **Returns**

            cmds: *str*
                A string, separated with new lines, with pair_coeff for each
                morse command possible within this parameter set.
        '''
        lammps_command = []
        for i in range(len(self.coul_params)):
            if not ffh.check_restriction(self.coul_params[i], self.restrict):
                continue
            charge_i = self.coul_params[i].charge
            index = self.restrict.index(self.coul_params[i].index)
            lammps_command.append('set type %d charge %f' %
                                  (index + 1, charge_i))
        lammps_command = "\n".join(lammps_command)
        return lammps_command
Пример #5
0
    def __repr__(self):
        '''
        This prints out a representation of the parameter object, in the format
        that is output to the smrff parameter file.

        **Returns**

            params: *str*
                A string representation of parameters.
        '''
        params = ""
        param_list = self._get_param_list()
        if self.opls_structure_dict is None:
            restrict_structures = None
        else:
            restrict_structures = [
                v for k, v in self.opls_structure_dict.items()
                if k in self.restrict
            ]

        # Handle smrff list
        if param_list is not None:
            for param_type, param_string in zip(*param_list):
                if param_type is not None:
                    params = params.strip() + "\n" + param_string + "\n"
                    if param_string in OPLS_STRUCTURES:
                        params += "\n".join([
                            str(p) for p in param_type
                            if ffh.check_restriction(p, restrict_structures)
                        ])
                    else:
                        params += "\n".join([
                            str(p) for p in param_type
                            if ffh.check_restriction(p, self.restrict)
                        ])
                    params += "\nEND"

        return params.strip()
Пример #6
0
    def dump_lj_cut_coul_cut(self):
        '''
        This function will get the lammps command line argument for
        lj/cut/coul/cut of everything within the Parameters object.

        **Parameters**

            None

        **Returns**

            cmds: *str*
                A string, separated with new lines, with pair_coeff for each
                lj/cut/coul/cut command possible within this parameter set.
        '''

        lammps_command = []

        for i in range(len(self.lj_params)):
            for j in range(i, len(self.lj_params)):
                if not ffh.check_restriction(self.lj_params[i], self.restrict):
                    continue
                if not ffh.check_restriction(self.lj_params[j], self.restrict):
                    continue
                sigma_ij = (self.lj_params[i].sigma *
                            self.lj_params[j].sigma)**0.5
                epsilon_ij = (self.lj_params[i].epsilon *
                              self.lj_params[j].epsilon)**0.5
                type_i = int(self.restrict.index(self.lj_params[i].index) + 1)
                type_j = int(self.restrict.index(self.lj_params[j].index) + 1)
                type_i, type_j = sorted([type_i, type_j])
                lammps_command.append(
                    'pair_coeff %d %d lj/cut/coul/cut %f %f' %
                    (type_i, type_j, epsilon_ij, sigma_ij))

        lammps_command = "\n".join(lammps_command)
        return lammps_command
Пример #7
0
    def unpack(self, with_indices=False, with_bounds=False):
        '''
        Unpacks the parameters object into a 1D array for parameterization.
        This means that the indices are not included during unpacking!  Note,
        this can be overridden though if needed.

        **Parameters**

            with_indices: *bool, optional*
                Whether to also include the indices in the flat array.
            with_bounds: *bool, optional*
                Whether to also output the bounds for the parameters.

        **Returns**

            flat_array: *list, float/int*
                A list of floats/ints of our parameters.
            bounds_lower: *list, float/int*
                If with_bounds is specified, then the lower bounds are returned.
            bounds_upper: *list, float/int*
                If with_bounds is specified, then the upper bounds are returned.
        '''

        verify_tersoff_2body_symmetry(self.tersoff_params)

        param_types, param_string_identifiers = self._get_param_list(
            trim_tersoff_2body=True)
        out, bounds_lower, bounds_upper = [], [], []
        for param_type in param_types:
            for p in param_type:
                if not ffh.check_restriction(p, self.restrict):
                    continue
                if with_bounds:
                    local_out, local_bounds_l, local_bounds_u = p.unpack(
                        with_indices, with_bounds=with_bounds)
                    out += local_out
                    bounds_lower += local_bounds_l
                    bounds_upper += local_bounds_u
                else:
                    out += p.unpack(with_indices)

        if with_bounds:
            return out, bounds_lower, bounds_upper
        else:
            return out
Пример #8
0
    def dump_morse(self):
        '''
        This function will get the lammps command line argument for
        morse of everything within the Parameters object.

        **Parameters**

            None

        **Returns**

            cmds: *str*
                A string, separated with new lines, with pair_coeff for each
                morse command possible within this parameter set.
        '''
        lammps_command = []
        for k in range(len(self.morse_params)):
            if not ffh.check_restriction(self.morse_params[k], self.restrict):
                continue

            index_i = self.restrict.index(str(
                self.morse_params[k].indices[0])) + 1
            index_j = self.restrict.index(str(
                self.morse_params[k].indices[1])) + 1

            index_i, index_j = sorted([index_i, index_j])

            D0 = self.morse_params[k].D0
            alpha = self.morse_params[k].alpha
            r0 = self.morse_params[k].r0
            rc = self.morse_params[k].rc
            lammps_command.append('pair_coeff ' + str(index_i) + ' ' +
                                  str(index_j) + ' morse %f %f %f %f' %
                                  (D0, alpha, r0, rc))
        lammps_command = "\n".join(lammps_command)
        return lammps_command