Exemplo n.º 1
0
    def load_smrff(cls, pfile, pfptr=None, restrict=None):
        '''
        Given a parameter file, import the Morse 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)
                (For programmer: The name of this parameter must be changed. It is hard to understand.)
        **Returns**
            Morse_objs: *list, Morse*, or *None*
                Returns a list of Morse 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 pfptr is not None:
            pfile = smrff_utils.parse_pfile(pfptr)
        if MORSE_PFILE_ID not in pfile:
            return []
        pfile = pfile[pfile.index(MORSE_PFILE_ID):]
        pfile = pfile[:pfile.index(END_ID)].split("\n")[1:-1]

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

        return [
            cls(indices=indices, D0=D0, alpha=alpha, r0=r0, rc=rc, line=None)
            for indices, D0, alpha, r0, rc in pfile
            if check_restriction(indices, restrict)
        ]
Exemplo n.º 2
0
    def load_smrff(cls, pfile, pfptr=None, restrict=None):
        '''
        Given a parameter file, inport the LJ 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**
            lj_objs: *list, 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 pfptr is not None:
            pfile = smrff_utils.parse_pfile(pfptr)
        if LJ_PFILE_ID not in pfile:
            return []

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

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

        return [
            cls(index=index, sigma=sigma, epsilon=epsilon)
            for index, sigma, epsilon in pfile
            if check_restriction(index, restrict)
        ]
Exemplo n.º 3
0
    def load_smrff(cls,
                   parsed_file,
                   pfile_name=None,
                   restrict=None,
                   adjust_range=False):
        '''
        Given a parameter file, import the Morse 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 default bounds range to account for
                read in values from a file being out of bounds.

        **Returns**

            Morse_objs: *list,* :class:`squid.forcefields.morse.Morse`, or *None*
                Returns a list of Morse objects if possible, else None.
        '''
        import squid.forcefields.smrff as smrff_utils

        # Ensure correct parsed_file format, and that we even need to parse it.
        if pfile_name is not None:
            parsed_file = smrff_utils.parse_pfile(pfile_name)
        if MORSE_PFILE_ID not in parsed_file:
            return []
        parsed_file = parsed_file[parsed_file.index(MORSE_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(indices=indices,
                D0=D0,
                alpha=alpha,
                r0=r0,
                rc=rc,
                line=None,
                adjust_range=adjust_range)
            for indices, D0, alpha, r0, rc in parsed_file
            if check_restriction(indices, restrict)
        ]
Exemplo n.º 4
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)
        ]
Exemplo n.º 5
0
    def load_smrff(cls, pfile, pfptr=None, restrict=None):
        '''
        Given a parameter file, inport the smooth 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**
            smooth_objs: *list, smooth*, or *None*
                Returns a list of smooth 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 pfptr is not None:
            pfile = smrff_utils.parse_pfile(pfptr)
        if SMOOTH_PFILE_ID not in pfile:
            return []

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

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

        return [
            cls(smooth_index,
                atom_i,
                atom_j,
                r_in,
                d_in,
                gcut,
                r_out=r_out,
                d_out=d_out,
                lr=lr,
                c_r=c_r,
                c_d=c_d,
                c_lr=c_lr,
                c_gcut=c_gcut,
                c_s_index=c_s_index)
            for smooth_index, atom_i, atom_j, r_in, d_in, r_out, d_out, c_r,
            c_d, gcut, c_gcut, lr, c_lr, c_s_index in pfile
            if check_restriction(atom_i, restrict)
            and check_restriction(atom_j, restrict)
        ]
Exemplo n.º 6
0
    def load_smrff(cls, parsed_file, pfile_name=None, restrict=None):
        '''
        Given a parameter file, inport the smooth 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**

            smooth_objs: *list,* :class:`squid.forcefields.sinSmooth.lr.SmoothSinInOut`, or *None*
                Returns a list of smooth objects if possible, else None.
        '''
        import squid.forcefields.smrff as smrff_utils

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

        parsed_file = parsed_file[parsed_file.index(SMOOTH_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
            if is_numeric(line.split()[0]) and len(line.split()) == 9
        ]

        return [
            cls(smooth_index, atom_i, atom_j, r_in, d_in, gcut_in, r_out,
                d_out, gcut_out) for smooth_index, atom_i, atom_j, r_in, d_in,
            gcut_in, r_out, d_out, gcut_out in parsed_file
            if check_restriction(atom_i, restrict)
            and check_restriction(atom_j, restrict)
        ]
Exemplo n.º 7
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)
        ]
Exemplo n.º 8
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)
        ]