Exemple #1
0
    def load_smrff(cls,
                   parsed_file,
                   pfile_name=None,
                   restrict=None,
                   adjust_range=False):
        '''
        Given a parameter file, inport the coulomb parameters if possible.

        **Parameters**

            parsed_file: *str*
                A parsed smrff parameter file input string (no comments or
                trailing white spaces)
            pfile_name: *str*
                The name of a parameter file to be parsed.  If specified,
                then parsed_file is ignored (you may simply pass None as
                parsed_file).
            restrict: *list, str, optional*
                A list of atom labels to include when loading.  If not
                specified, everything is loaded.
            adjust_range: *bool, optional*
                Whether to adjust the parameter bounds to account for read
                in values, or not.

        **Returns**

            lj_objs: *list,* :class:`squid.forcefields.lj.LJ`, or *None*
                Returns a list of LJ objects if possible, else None.
        '''
        import squid.forcefields.smrff as smrff_utils

        # Ensure correct pfile format, and that we even need to parse it.
        if pfile_name is not None:
            parsed_file = smrff_utils.parse_pfile(pfile_name)
        if LJ_PFILE_ID not in parsed_file:
            return []

        parsed_file = parsed_file[parsed_file.index(LJ_PFILE_ID):]
        parsed_file = parsed_file[:parsed_file.index(END_ID)].split("\n")[1:-1]

        parsed_file = [cls.parse_line(line) for line in parsed_file]

        return [
            cls(index=index,
                sigma=sigma,
                epsilon=epsilon,
                adjust_range=adjust_range)
            for index, sigma, epsilon in parsed_file
            if check_restriction(index, restrict)
        ]
Exemple #2
0
    def load_opls(cls, dihedral_types, pfptr=None, restrict=None):
        """
        Given a parameter file, inport the Dihedral parameters if possible.
        **Parameters**
            dihedral_types: *list,* :class:`structures.Struct`
                Dihedral types from a parsed opls parameter file.
            pfptr: *str*
                The name of a parameter file to be parsed.  If specified,
                then pfile is ignored (you may simply pass None as pfile).
        **Returns**
            dihedral_objs: *list, Dihedral*, or *None*
                Returns a list of Dihedral objects if possible, else None.
        """
        import squid.forcefields.opls as opls_utils
        if pfptr is not None:
            _, _, _, dihedral_types = opls_utils.parse_pfile(pfptr)

        return [
            cls(indices=t.index2s, energies=t.e, equilibs=[])
            for t in dihedral_types if check_restriction(t.index2s, restrict)
        ]
Exemple #3
0
    def load_smrff(cls, parsed_file, pfile_name=None, restrict=None):
        '''
        Given a parameter file, inport the coulomb parameters if possible.

        **Parameters**

            parsed_file: *str*
                A parsed smrff parameter file input string (no comments or
                trailing white spaces)
            pfile_name: *str*
                The name of a parameter file to be parsed.  If specified,
                then parsed_file is ignored (you may simply pass None as
                parsed_file).
            restrict: *list, str, optional*
                A list of atom labels to include when loading.  If not
                specified, everything is loaded.

        **Returns**

            coul_objs: *list,* :class:`squid.forcefields.coulomb.Coul`, or *None*
                Returns a list of Coul objects if possible, else None.
        '''
        import squid.forcefields.smrff as smrff_utils

        # Ensure correct pfile format, and that we even need to parse it.
        if pfile_name is not None:
            parsed_file = smrff_utils.parse_pfile(pfile_name)
        if COUL_PFILE_ID not in parsed_file:
            return []

        parsed_file = parsed_file[parsed_file.index(COUL_PFILE_ID):]
        parsed_file = parsed_file[:parsed_file.index(END_ID)].split("\n")[1:-1]

        parsed_file = [cls.parse_line(line) for line in parsed_file]

        return [
            cls(index=index, charge=charge, element=element, mass=mass)
            for index, charge, element, mass in parsed_file
            if check_restriction(index, restrict)
        ]
Exemple #4
0
    def load_opls(cls, atom_types, pfptr=None, restrict=None):
        '''
        Given a parameter file, inport the LJ parameters if possible.
        **Parameters**
            atom_types: *list,* :class:`structures.Struct`
                Atom types from a parsed opls parameter file.
            pfptr: *str*
                The name of a parameter file to be parsed.  If specified,
                then pfile is ignored (you may simply pass None as pfile).
        **Returns**
            lj_objs: *list, LJ*, or *None*
                Returns a list of LJ objects if possible, else None.
        '''
        # Ensure correct pfile format, and that we even need to parse it.
        import squid.forcefields.opls as opls_utils

        if pfptr is not None:
            atom_types, _, _, _ = opls_utils.parse_pfile(pfptr)

        return [
            cls(index=t.index, sigma=t.vdw_r, epsilon=t.vdw_e)
            for t in atom_types if check_restriction(t, restrict)
        ]
Exemple #5
0
    def dump_pair_coeffs(self, restricts, map_to_lmp_index=True):
        '''
        Get the smrff lammps input line for this smooth function.  Specifically
        the pair_coeff line.

        **Parameters**

            restricts: *list, str*
                A list of the atom types and how they apply to LAMMPS.  For
                example, assume restricts = ["xA", "xB"], then atoms of
                index xA will be 1 in LAMMPS dumps and atoms of xB will be
                2 in LAMMPS dumps.
            map_to_lmp_index: *bool, optional*
                Whether to map the pair coeffs to the lmp indices or not.

        **Returns**

            pair_str: *str*
                The pair coefficients in LAMMPS input script line format.
        '''

        self.validate()

        # Handle restrict appropriately
        if self.atom_i != "*" and not check_restriction(
                self.atom_i, restricts):
            return ""
        if self.atom_j != "*" and not check_restriction(
                self.atom_j, restricts):
            return ""

        if self.atom_i is None:
            ai = "*"
        else:
            if map_to_lmp_index:
                ai = restricts.index(self.atom_i) + 1
            else:
                ai = self.atom_i
        if self.atom_j is None:
            aj = "*"
        else:
            if map_to_lmp_index:
                aj = restricts.index(self.atom_j) + 1
            else:
                aj = self.atom_j

        if self.lr is None or 'inout' in self.lr:
            style_name = 'sin_inout'
        elif self.lr == 'l':
            style_name = 'sin_l'
        elif self.lr == 'r':
            style_name = 'sin_r'
        else:
            raise Exception("Error - somehow style name is unknown")

        dists = [self.r_in, self.d_in]
        dists = ' '.join(["%.2f" % x for x in dists])

        line = "pair_coeff %s %s %s %d %s"\
               % (ai, aj, style_name, self.smooth_index, dists)

        return line
Exemple #6
0
    def dump_pair_coeffs(self, restricts, skip_restricts=False):
        '''
        Get the smrff lammps input line for this smooth function.  Specifically
        the pair_coeff line.
        '''

        self.validate()

        # Handle restrict appropriately
        if self.atom_i is not "*" and not check_restriction(
                self.atom_i, restricts):
            return ""
        if self.atom_j is not "*" and not check_restriction(
                self.atom_j, restricts):
            return ""

        if self.atom_i is None:
            ai = "*"
        else:
            if not skip_restricts:
                ai = restricts.index(self.atom_i) + 1
            else:
                ai = self.atom_i
        if self.atom_j is None:
            aj = "*"
        else:
            if not skip_restricts:
                aj = restricts.index(self.atom_j) + 1
            else:
                aj = self.atom_j

        if self.lr is None or 'inout' in self.lr:
            style_name = 'sin_inout'
        elif self.lr == 'l':
            style_name = 'sin_l'
        elif self.lr == 'r':
            style_name = 'sin_r'
        else:
            raise Exception("Error - somehow style name is unknown")

        dists = [self.r_in, self.d_in]
        if style_name == 'sin_inout':
            dists += [self.r_out, self.d_out]
        offset_couple = style_name == 'sin_inout'
        dists = ' '.join(["%.2f" % x for x in dists])

        line = "pair_coeff %s %s %s %d %s" % (ai, aj, style_name,
                                              self.smooth_index, dists)

        if self.coupled:
            if self.c_lr is None or 'inout' in self.c_lr:
                style_name = 'sin_inout'
            elif self.c_lr == 'l':
                style_name = 'sin_l'
            elif self.c_lr == 'r':
                style_name = 'sin_r'
            else:
                raise Exception("Error - somehow style name is unknown")

            dists = [
                self.r_in, self.d_in, self.r_out, self.d_out, self.c_r,
                self.c_d
            ]
            if offset_couple:
                dists = dists[2:]
            if None in dists:
                dists = dists[:dists.index(None)]
            dists = ' '.join(["%.2f" % x for x in dists])

            line += "\n"
            line += "pair_coeff %s %s %s %d %s" % (ai, aj, style_name,
                                                   self.c_s_index, dists)

        return line
Exemple #7
0
    def load_smrff(cls, pfile, pfptr=None, restrict=None):
        '''
        Given a parameter file, inport the tersoff parameters if possible.

        **Parameters**

            pfile: *str*
                A parsed smrff parameter file input string (no comments or
                trailing white spaces)
            pfptr: *str*
                The name of a parameter file to be parsed.  If specified,
                then pfile is ignored (you may simply pass None as pfile).

        **Returns**

            tersoff_objs: *list, Tersoff*, or *None*
                Returns a list of Tersoff objects if possible, else None.
        '''
        # Ensure correct pfile format, and that we even need to parse it.
        if pfptr is not None:
            pfile = smrff_utils.parse_pfile(pfptr)
        if TERSOFF_PFILE_ID not in pfile:
            return []

        pfile = pfile[pfile.index(TERSOFF_PFILE_ID):]
        pfile = pfile[:pfile.index(END_ID)].split("\n")[1:-1]

        # Because Tersoff may be split into two lines, we need additional parsing
        # Each line should have 17 things in it:
        #    3 indices, 14 tersoff parameters
        pfile = ' '.join(pfile).strip().split()
        assert len(
            pfile
        ) % 17 == 0, "Error - there appears to be an issue in how the Tersoff parameters are defined."

        pfile = [
            ' '.join(pfile[i * 17:(i + 1) * 17])
            for i in range(int(len(pfile) / 17))
        ]
        pfile = [cls.parse_line(line) for line in pfile]

        # indices, m, gamma, lambda3, c, d, costheta0, n, beta, lambda2, B, R, D, lambda1, A

        return [
            cls(indices=indices,
                m=m,
                gamma=gamma,
                lambda3=lambda3,
                c=c,
                d=d,
                costheta0=costheta0,
                n=n,
                beta=beta,
                lambda2=lambda2,
                B=B,
                R=R,
                D=D,
                lambda1=lambda1,
                A=A) for indices, m, gamma, lambda3, c, d, costheta0, n, beta,
            lambda2, B, R, D, lambda1, A in pfile
            if check_restriction(indices, restrict)
        ]