class MPINTLammps(LAMMPS, MSONable):
    """
    setup LAMMPS for given structure and parameters
    extends ase.calculators.lammpsrun.LAMMPS
    """

    def __init__(
        self, structure, parameters={}, label="mpintlmp", specorder=None, always_triclinic=True, no_data_file=False
    ):
        LAMMPS.__init__(
            self,
            label=label,
            parameters=parameters,
            specorder=specorder,
            files=[],
            always_triclinic=always_triclinic,
            no_data_file=no_data_file,
        )
        self.structure = structure
        self.atoms = AseAtomsAdaptor().get_atoms(structure)
        self.label = label
        self.parameters = parameters
        self.specorder = specorder
        self.always_triclinic = always_triclinic
        self.no_data_file = no_data_file
        self.charges = None
        if "charges" in self.parameters:
            self.charges = self.parameters["charges"]

    def write_lammps_data(self, f):
        """
        write lammps structure data
        from ase with custom modifications
        """
        f.write(f.name + " (written by mpinterfaces) \n\n")
        symbols = self.atoms.get_chemical_symbols()
        n_atoms = len(symbols)
        f.write("%d \t atoms \n" % n_atoms)
        if self.specorder is None:
            species = [tos.symbol for tos in self.structure.types_of_specie]
        else:
            species = self.specorder
        n_atom_types = len(species)
        f.write("%d  atom types\n" % n_atom_types)
        p = prism(self.atoms.get_cell())
        xhi, yhi, zhi, xy, xz, yz = p.get_lammps_prism_str()
        f.write("0.0 %s  xlo xhi\n" % xhi)
        f.write("0.0 %s  ylo yhi\n" % yhi)
        f.write("0.0 %s  zlo zhi\n" % zhi)
        if self.always_triclinic or p.is_skewed():
            f.write("%s %s %s  xy xz yz\n" % (xy, xz, yz))
        f.write("\n\n")
        f.write("Atoms \n\n")
        for i, r in enumerate(map(p.pos_to_lammps_str, self.atoms.get_positions())):
            c = 0.0
            if self.charges:
                c = self.charges[symbols[i]]
            s = species.index(symbols[i]) + 1
            if "atom_style" in self.parameters:
                if self.parameters["atom_style"] == "charge":

                    f.write("%6d %3d %6f %s %s %s\n" % ((i + 1, s, c) + tuple(r)))
                else:
                    f.write("%6d %3d %s %s %s\n" % ((i + 1, s) + tuple(r)))
        if self.atoms.get_velocities() is not None:
            f.write("\n\nVelocities \n\n")
            for i, v in enumerate(self.atoms.get_velocities()):
                f.write("%6d %s %s %s\n" % ((i + 1,) + tuple(v)))
        f.close()

    #        self.mplmp.write_lammps_in(lammps_in=lmp_in_fd,lammps_in1=lmp_in_fd1,lammps_in2=lmp_in_fd2,
    #                                   lammps_trj=lmp_trj_name,
    #                                   lammps_data=lmp_data_name)
    #   self.mplmp.write_lammps_in(lammps_in=lmp_in_fd,lammps_in1=lmp_in_fd1,
    #                                   lammps_trj=lmp_trj_name,
    #                                   lammps_data=lmp_data_name)

    def write_lammps_in(self, lammps_in=None, lammps_in1=None, lammps_in2=None, lammps_trj=None, lammps_data=None):
        """
        write lammps input file
        from ase with custom modifications
        """
        f = lammps_in
        f1 = lammps_in1  # potential.mod
        f2 = lammps_in2
        parameters = self.parameters
        if "units" in parameters:
            if parameters["units"] == "real":
                f.write(
                    ('variable dump_file string "%s"\n' % lammps_trj)
                    + ("variable up  equal 1.0e-8\n")
                    + ("variable cfac  equal 1.01325e-4\n")
                    + ("variable cunits  string GPa\n")
                    + ("variable etol  equal 0\n")
                    + ("variable ftol  equal 1.0e-10\n")
                    + ("variable maxiter equal 1000\n")
                    + ("variable maxeval equal 10000\n")
                    + ("variable dmax equal 1.0e-2\n")
                    + ('variable data_file string "%s"\n' % lammps_data)
                )
        else:

            f.write(
                ('variable dump_file string "%s"\n' % lammps_trj)
                + ("variable up  equal 1.0e-8\n")
                + ("variable cfac  equal 1.0e-4\n")
                + ("variable cunits  string GPa\n")
                + ("variable etol  equal 0\n")
                + ("variable ftol  equal 1.0e-10\n")
                + ("variable maxiter equal 1000\n")
                + ("variable maxeval equal 10000\n")
                + ("variable dmax equal 1.0e-2\n")
                + ('variable data_file string "%s"\n' % lammps_data)
            )
        pbc = self.atoms.get_pbc()
        if "control_file" in parameters:
            f2.write("include %s \n" % parameters["control_file"])
        # f2.write('include /home/kamal/inelast.mod \n')
        if "units" in parameters:
            f.write("units %s \n" % parameters["units"])
        else:
            f.write("units metal \n")
        # f.write('units metal \n')
        if "atom_style" in parameters:
            f.write("atom_style %s \n" % parameters["atom_style"])
        else:
            f.write("atom_style atomic \n")
        if "boundary" in parameters:
            f.write("boundary %s \n" % parameters["boundary"])
        else:
            f.write("boundary %c %c %c \n" % tuple("sp"[x] for x in pbc))
        f.write("atom_modify sort 0 0.0 \n")
        for key in ("neighbor", "newton"):
            if key in parameters:
                f.write("%s %s \n" % (key, parameters[key]))
        f.write("\n")
        # If no_data_file,
        # write the simulation box and the atoms
        if self.no_data_file:
            p = self.prism
            f.write("lattice sc 1.0\n")
            xhi, yhi, zhi, xy, xz, yz = p.get_lammps_prism_str()
            if self.always_triclinic or p.is_skewed():
                f.write("region asecell prism 0.0 %s 0.0 %s 0.0 %s " % (xhi, yhi, zhi))
                f.write("%s %s %s side in units box\n" % (xy, xz, yz))
            else:
                f.write(("region asecell block 0.0 %s 0.0 %s 0.0 %s " "side in units box\n") % (xhi, yhi, zhi))
            symbols = self.atoms.get_chemical_symbols()

            ############KAMAL###########################################
            #        species = [tos.symbol for tos in self.structure.types_of_specie]
            #
            #        for i, r in enumerate(map(p.pos_to_lammps_str,
            #                                  self.atoms.get_positions())):
            #            s = species.index(symbols[i]) + 1
            ################################################
            if self.specorder is None:
                species = [tos.symbol for tos in self.structure.types_of_specie]
            else:
                species = self.specorder
            n_atom_types = len(species)
            species_i = dict([(s, i + 1) for i, s in enumerate(species)])
            f.write("create_box %i asecell\n" % n_atom_types)
            for s, pos in zip(symbols, self.atoms.get_positions()):
                f.write(
                    "create_atoms %i single %s %s %s units box\n" % ((species_i[s],) + p.pos_to_lammps_fold_str(pos))
                )
        else:
            f.write("read_data %s\n" % lammps_data)
        # interaction
        f.write("\n### interactions \n")
        if "lib" in parameters:
            lib = parameters["lib"]
            f1.write("%s \n" % lib)
        if ("pair_style" in parameters) and ("pair_coeff" in parameters):
            pair_style = parameters["pair_style"]
            f1.write("pair_style %s \n" % pair_style)
            symbols = self.atoms.get_chemical_symbols()
            species = set(symbols)
            # species = [tos.symbol.replace("Mo","M") for tos in self.structure.types_of_specie]
            species = [tos.symbol for tos in self.structure.types_of_specie]
            tag = ""
            for i in species:
                tag = tag + " " + i
            pair_coef = "* * " + str(parameters["pair_coeff"]) + " " + tag
            f1.write("pair_coeff %s \n" % pair_coef)

            #            for pair_coeff in parameters['pair_coeff']:
            #                f.write('pair_coeff %s \n' % pair_coeff)
            #

            #            if 'mass' in parameters:
            #                for mass in parameters['mass']:
            #                    f.write('mass %s \n' % mass)
            masses = set(self.atoms.get_masses())
            count = 0
            for i in masses:
                count = count + 1
                f.write("mass" + " " + str(count) + " " + str(i) + "\n")
        else:
            # default interaction
            f.write("pair_style lj/cut 2.5 \n" + "pair_coeff * * 1 1 \n" + "mass * 1.0 \n")
        #   f.write('\n### run\n')
        #   if 'fix' in parameters:
        #       if parameters['fix']:
        #           for i in parameters['fix']:
        #               f.write('fix %s\n' % i)
        #   else:
        #       f.write('fix fix_nve all nve\n')
        f1.write("neighbor 1.0 nsq\n")
        f1.write("neigh_modify once no every 1 delay 0 check yes\n")
        f1.write("min_style  cg\n")
        f1.write("min_modify           dmax ${dmax} line quadratic\n")
        f1.write("thermo          1\n")
        f1.write("thermo_style custom step temp press cpu pxx pyy pzz pxy pxz pyz ke pe etotal vol lx ly lz atoms\n")
        # f1.write('thermo_style custom step temp pe press pxx pyy pzz pxy pxz pyz lx ly lz vol\n' )
        f1.write("thermo_modify norm no\n")
        #   if 'thermo_style' in parameters:
        #       f.write('thermo_style %s\n' % parameters['thermo_style'])
        #   else:
        #       f.write(('thermo_style custom %s\n') %
        #               (' '.join(self._custom_thermo_args)))
        #   if 'thermo_modify' in parameters:
        #       f.write('thermo_modify %s\n' % parameters['thermo_modify'])
        #   else:
        #       f.write('thermo_modify flush yes\n')
        #   if 'thermo' in parameters:
        #       f.write('thermo %s\n' % parameters['thermo'])
        #   else:
        #       f.write('thermo 1\n')
        #   if 'minimize' in parameters:
        #       f.write('minimize %s\n' % parameters['minimize'])
        #   if 'run' in parameters:
        #       f.write('run %s\n' % parameters['run'])
        #   if not (('minimize' in parameters) or ('run' in parameters)):
        #       f.write('run 0\n')
        #   if 'dump' in parameters:
        #       f.write('dump %s\n' % parameters['dump'])
        #   else:
        #       f.write('dump dump_all all custom 1 %s id type x y z vx vy vz fx fy fz\n' % lammps_trj)
        #   f.write('print __end_of_ase_invoked_calculation__\n')
        #   f.write('log /dev/stdout\n')
        if "fix" in parameters:
            if parameters["fix"]:
                for i in parameters["fix"]:
                    f1.write("fix %s\n" % i)
        f.close()

    def as_dict(self):
        d = dict(
            structure=self.structure.as_dict(),
            parameters=self.parameters,
            label=self.label,
            specorder=self.specorder,
            always_triclinic=self.always_triclinic,
            no_data_file=self.no_data_file,
        )
        d["@module"] = self.__class__.__module__
        d["@class"] = self.__class__.__name__
        return d

    @classmethod
    def from_dict(cls, d):
        structure = Structure.from_dict(d["structure"])
        return MPINTLammps(
            structure,
            parameters=d["parameters"],
            label=d["label"],
            specorder=d["specorder"],
            always_triclinic=d["always_triclinic"],
            no_data_file=d["no_data_file"],
        )
Beispiel #2
0
def write_lammps_in(
    structure=None,
    lammps_in=None,
    lammps_in1=None,
    lammps_in2=None,
    lammps_trj=None,
    lammps_data=None,
    parameters={},
):
    """
        write lammps input file
        from ase with custom modifications
        LAMMPS input is devided into three parts

        Args:
            structure: Structure object
            lammps_in: generally"init.mod", with unit and conversion factor information
            lammps_in1: generally "potential.mod", with force-field/potential style and element tyoe information
            lammps_in2: generally "in.elastic", a generic main input file to be fed in LAMMPS usin lmp_*<...,parameters['exec']
            parameters: input parameters
            
        """
    structure.sort()
    f = open(lammps_in, "w")
    f1 = open(lammps_in1, "w")  # potential.mod
    f2 = open(lammps_in2, "w")
    f.write(
        ('variable dump_file string "%s"\n' % lammps_trj)
        + ("variable up  equal 1.0e-6\n")
        + ("variable cfac  equal 1.0e-4\n")
        + ("variable cunits  string GPa\n")
        + ("variable etol  equal 0\n")
        + ("variable ftol  equal 1.0e-10\n")
        + ("variable maxiter equal 1000\n")
        + ("variable maxeval equal 10000\n")
        + ("variable dmax equal 1.0e-2\n")
        + ('variable data_file string "%s"\n' % "data")
    )
    atoms = AseAtomsAdaptor().get_atoms(structure)
    pbc = atoms.get_pbc()
    if "control_file" in parameters:
        f2.write("include %s \n" % parameters["control_file"])
    if "units" in parameters:
        f.write("units %s \n" % parameters["units"])
    else:
        f.write("units metal \n")
    if "atom_style" in parameters:
        f.write("atom_style %s \n" % parameters["atom_style"])
    else:
        f.write("atom_style atomic \n")
    if "boundary" in parameters:
        f.write("boundary %s \n" % parameters["boundary"])
    else:
        f.write("boundary %c %c %c \n" % tuple("sp"[x] for x in pbc))
    f.write("atom_modify sort 0 0.0 \n")
    for key in ("neighbor", "newton"):
        if key in parameters:
            f.write("%s %s \n" % (key, parameters[key]))
    f.write("\n")
    # If no_data_file,
    # write the simulation box and the atoms
    species = [tos for tos in Poscar(structure).site_symbols]
    # species = [tos.symbol for tos in structure.types_of_specie]
    n_atom_types = len(species)
    species_i = dict([(s, i + 1) for i, s in enumerate(species)])
    f.write("read_data %s\n" % "data")
    # interaction
    f.write("\n### interactions \n")
    if "lib" in parameters:
        lib = parameters["lib"]
        f1.write("%s \n" % lib)
    if ("pair_style" in parameters) and ("pair_coeff" in parameters):
        pair_style = parameters["pair_style"]
        f1.write("pair_style %s \n" % pair_style)
        symbols = atoms.get_chemical_symbols()
        # species = [tos.symbol.replace("Mo","M") for tos in structure.types_of_specie] #For REBO Mo-S
        # species = [tos.symbol for tos in structure.types_of_specie]
        print("site symbolss", Poscar(structure).site_symbols)
        species = [tos for tos in Poscar(structure).site_symbols]
        if parameters["pair_style"] == "rebomos":

            species = [tos.replace("Mo", "M") for tos in Poscar(structure).site_symbols]
        tag = ""
        for i in species:
            tag = tag + " " + i
        pair_coef = "* * " + str(parameters["pair_coeff"]) + " " + tag
        f1.write("pair_coeff %s \n" % pair_coef)

        masses = []
        for m in atoms.get_masses():
            if m not in masses:
                masses.append(m)
        count = 0
        for i in masses:
            count = count + 1
            f.write("mass" + " " + str(count) + " " + str(i) + "\n")
    else:
        # default interaction
        f.write("pair_style lj/cut 2.5 \n" + "pair_coeff * * 1 1 \n" + "mass * 1.0 \n")
    f1.write("neighbor 1.0 nsq\n")
    f1.write("neigh_modify once no every 1 delay 0 check yes\n")
    if "min" not in parameters:
        f1.write("min_style  cg\n")
        f1.write("min_modify           dmax ${dmax} line quadratic\n")
    f1.write("thermo          1\n")
    f1.write(
        "thermo_style custom step temp press cpu pxx pyy pzz pxy pxz pyz ke pe etotal vol lx ly lz atoms\n"
    )
    # f1.write('thermo_style custom step temp pe press pxx pyy pzz pxy pxz pyz lx ly lz vol\n' )
    f1.write("thermo_modify norm no\n")
    #   if 'thermo_style' in parameters:
    #       f.write('thermo_style %s\n' % parameters['thermo_style'])
    #   else:
    #       f.write(('thermo_style custom %s\n') %
    #               (' '.join(self._custom_thermo_args)))
    #   if 'thermo_modify' in parameters:
    #       f.write('thermo_modify %s\n' % parameters['thermo_modify'])
    #   else:
    #       f.write('thermo_modify flush yes\n')
    #   if 'thermo' in parameters:
    #       f.write('thermo %s\n' % parameters['thermo'])
    #   else:
    #       f.write('thermo 1\n')
    #   if 'minimize' in parameters:
    #       f.write('minimize %s\n' % parameters['minimize'])
    #   if 'run' in parameters:
    #       f.write('run %s\n' % parameters['run'])
    #   if not (('minimize' in parameters) or ('run' in parameters)):
    #       f.write('run 0\n')
    #   if 'dump' in parameters:
    #       f.write('dump %s\n' % parameters['dump'])
    #   else:
    #       f.write('dump dump_all all custom 1 %s id type x y z vx vy vz fx fy fz\n' % lammps_trj)
    #   f.write('print __end_of_ase_invoked_calculation__\n')
    #   f.write('log /dev/stdout\n')
    if "fix" in parameters:
        if parameters["fix"]:
            for i in parameters["fix"]:
                f1.write("fix %s\n" % i)
    f.close()
    f1.close()
    f2.close()
Beispiel #3
0
class MPINTLammps(LAMMPS, MSONable):
    """
    setup LAMMPS for given structure and parameters
    extends ase.calculators.lammpsrun.LAMMPS
    """
    def __init__(self, structure, parameters={},
                 label='mpintlmp', specorder=None,
                 always_triclinic=True, no_data_file=False):
        LAMMPS.__init__(self, label=label,
                        parameters=parameters,
                        specorder=specorder, files=[],
                        always_triclinic=always_triclinic,
                        no_data_file=no_data_file)        
        self.structure = structure
        self.atoms = AseAtomsAdaptor().get_atoms(structure)
        self.label = label
        self.parameters = parameters
        self.specorder = specorder
        self.always_triclinic = always_triclinic
        self.no_data_file = no_data_file
        self.charges = None
        if 'charges' in self.parameters:
            self.charges = self.parameters['charges']
        
    def write_lammps_data(self, f):
        """
        write lammps structure data
        from ase with custom modifications
        """
        f.write(f.name + ' (written by mpinterfaces) \n\n')
        symbols = self.atoms.get_chemical_symbols()
        n_atoms = len(symbols)
        f.write('%d \t atoms \n' % n_atoms)
        if self.specorder is None:
            species = [tos.symbol
                       for tos in self.structure.types_of_specie]
        else:
            species = self.specorder
        n_atom_types = len(species)
        f.write('%d  atom types\n' % n_atom_types)
        p = prism(self.atoms.get_cell())
        xhi, yhi, zhi, xy, xz, yz = p.get_lammps_prism_str()
        f.write('0.0 %s  xlo xhi\n' % xhi)
        f.write('0.0 %s  ylo yhi\n' % yhi)
        f.write('0.0 %s  zlo zhi\n' % zhi)
        if self.always_triclinic or p.is_skewed():
            f.write('%s %s %s  xy xz yz\n' % (xy, xz, yz))
        f.write('\n\n')
        f.write('Atoms \n\n')
        for i, r in enumerate(map(p.pos_to_lammps_str,
                                  self.atoms.get_positions())):
            c = 0.0
            if self.charges:
                c = self.charges[symbols[i]]
            s = species.index(symbols[i]) + 1
            if 'atom_style' in self.parameters:
                if self.parameters['atom_style'] == 'charge':
                    
                    f.write('%6d %3d %6f %s %s %s\n' %
                            ((i+1, s, c)+tuple(r)) )
                else:
                    f.write('%6d %3d %s %s %s\n' % ((i+1, s)+tuple(r)))
        if self.atoms.get_velocities() is not None:
            f.write('\n\nVelocities \n\n')
            for i, v in enumerate(self.atoms.get_velocities()):
                f.write('%6d %s %s %s\n' % ((i+1,)+tuple(v)))
        f.close()


#        self.mplmp.write_lammps_in(lammps_in=lmp_in_fd,lammps_in1=lmp_in_fd1,lammps_in2=lmp_in_fd2,
#                                   lammps_trj=lmp_trj_name,
#                                   lammps_data=lmp_data_name)
#   self.mplmp.write_lammps_in(lammps_in=lmp_in_fd,lammps_in1=lmp_in_fd1,
#                                   lammps_trj=lmp_trj_name,
#                                   lammps_data=lmp_data_name)

    def write_lammps_in(self, lammps_in=None,lammps_in1=None,lammps_in2=None, lammps_trj=None,
                        lammps_data=None):
        """
        write lammps input file
        from ase with custom modifications
        """        
        f = lammps_in
        f1 = lammps_in1 #potential.mod
        f2 = lammps_in2
        parameters = self.parameters
        if 'units' in parameters:
           if  parameters['units']=='real':
                f.write(('variable dump_file string "%s"\n' % lammps_trj) +
                ('variable up  equal 1.0e-8\n' )+
                ('variable cfac  equal 1.01325e-4\n' )+
                ('variable cunits  string GPa\n' )+
                ('variable etol  equal 0\n' )+
                ('variable ftol  equal 1.0e-10\n' )+
                ('variable maxiter equal 1000\n' )+
                ('variable maxeval equal 10000\n' )+
                ('variable dmax equal 1.0e-2\n' )+
                ('variable data_file string "%s"\n' % lammps_data))
        else:
       
                 f.write(('variable dump_file string "%s"\n' % lammps_trj) +
                ('variable up  equal 1.0e-8\n' )+
                ('variable cfac  equal 1.0e-4\n' )+
                ('variable cunits  string GPa\n' )+
                ('variable etol  equal 0\n' )+
                ('variable ftol  equal 1.0e-10\n' )+
                ('variable maxiter equal 1000\n' )+
                ('variable maxeval equal 10000\n' )+
                ('variable dmax equal 1.0e-2\n' )+
                ('variable data_file string "%s"\n' % lammps_data))
        pbc = self.atoms.get_pbc()
        if 'control_file' in parameters:
            f2.write('include %s \n'%  parameters['control_file'])
        #f2.write('include /home/kamal/inelast.mod \n')
        if 'units' in parameters:
            f.write('units %s \n' % parameters['units'])
        else:
            f.write('units metal \n')
        #f.write('units metal \n')
        if 'atom_style' in parameters:
            f.write('atom_style %s \n' % parameters['atom_style'])
        else:
            f.write('atom_style atomic \n')
        if 'boundary' in parameters:
            f.write('boundary %s \n' % parameters['boundary'])
        else:
            f.write('boundary %c %c %c \n' %
                    tuple('sp'[x] for x in pbc))
        f.write('atom_modify sort 0 0.0 \n')
        for key in ('neighbor' ,'newton'):
            if key in parameters:
                f.write('%s %s \n' % (key, parameters[key]))
        f.write('\n')
        # If no_data_file,
        # write the simulation box and the atoms
        if self.no_data_file:
            p = self.prism
            f.write('lattice sc 1.0\n')
            xhi, yhi, zhi, xy, xz, yz = p.get_lammps_prism_str()
            if self.always_triclinic or p.is_skewed():
                f.write('region asecell prism 0.0 %s 0.0 %s 0.0 %s ' %
                        (xhi, yhi, zhi))
                f.write('%s %s %s side in units box\n' % (xy, xz, yz))
            else:
                f.write(('region asecell block 0.0 %s 0.0 %s 0.0 %s '
                         'side in units box\n') % (xhi, yhi, zhi))
            symbols = self.atoms.get_chemical_symbols()


############KAMAL###########################################
#        species = [tos.symbol for tos in self.structure.types_of_specie]
#
#        for i, r in enumerate(map(p.pos_to_lammps_str,
#                                  self.atoms.get_positions())):
#            s = species.index(symbols[i]) + 1
################################################
            if self.specorder is None:
                species = [tos.symbol for tos in self.structure.types_of_specie]
            else:
                species = self.specorder
            n_atom_types = len(species)
            species_i = dict([(s,i+1) for i,s in enumerate(species)])
            f.write('create_box %i asecell\n' % n_atom_types)
            for s, pos in zip(symbols, self.atoms.get_positions()):
                f.write('create_atoms %i single %s %s %s units box\n'%
                        ((species_i[s],)+p.pos_to_lammps_fold_str(pos)))
        else:
            f.write('read_data %s\n' % lammps_data)
        # interaction
        f.write('\n### interactions \n')
        if ( 'lib' in parameters ):
            lib = parameters['lib']
            f1.write('%s \n' % lib)
        if ( ('pair_style' in parameters) and ('pair_coeff' in parameters) ):
            pair_style = parameters['pair_style']
            f1.write('pair_style %s \n' % pair_style)
            symbols = self.atoms.get_chemical_symbols()
            species = set(symbols)
            #species = [tos.symbol.replace("Mo","M") for tos in self.structure.types_of_specie]
            species = [tos.symbol for tos in self.structure.types_of_specie]
            tag=''
            for i in species:
                tag=tag+' '+i
            pair_coef =  '* * '+str(parameters['pair_coeff'])+' '+tag
            f1.write('pair_coeff %s \n' % pair_coef)

        

#            for pair_coeff in parameters['pair_coeff']:
#                f.write('pair_coeff %s \n' % pair_coeff)
#            
       
 
            
#            if 'mass' in parameters:
#                for mass in parameters['mass']:
#                    f.write('mass %s \n' % mass)
            masses = set(self.atoms.get_masses())
            count=0
            for i in masses:
                count=count+1
                f.write('mass'+' '+str(count)+' '+str(i)+'\n')
        else:
            # default interaction
            f.write('pair_style lj/cut 2.5 \n' +
                    'pair_coeff * * 1 1 \n' +
                    'mass * 1.0 \n')
     #   f.write('\n### run\n')
     #   if 'fix' in parameters:
     #       if parameters['fix']:
     #           for i in parameters['fix']:
     #               f.write('fix %s\n' % i)
     #   else:
     #       f.write('fix fix_nve all nve\n')
        f1.write('neighbor 1.0 nsq\n' )
        f1.write('neigh_modify once no every 1 delay 0 check yes\n' )
        f1.write('min_style  cg\n' )
        f1.write('min_modify           dmax ${dmax} line quadratic\n' )
        f1.write('thermo          1\n' )
        f1.write('thermo_style custom step temp press cpu pxx pyy pzz pxy pxz pyz ke pe etotal vol lx ly lz atoms\n' )
        #f1.write('thermo_style custom step temp pe press pxx pyy pzz pxy pxz pyz lx ly lz vol\n' )
        f1.write('thermo_modify norm no\n' )
     #   if 'thermo_style' in parameters:
     #       f.write('thermo_style %s\n' % parameters['thermo_style'])
     #   else:
     #       f.write(('thermo_style custom %s\n') %
     #               (' '.join(self._custom_thermo_args)))
     #   if 'thermo_modify' in parameters:
     #       f.write('thermo_modify %s\n' % parameters['thermo_modify'])
     #   else:
     #       f.write('thermo_modify flush yes\n')
     #   if 'thermo' in parameters:
     #       f.write('thermo %s\n' % parameters['thermo'])
     #   else:
     #       f.write('thermo 1\n')            
     #   if 'minimize' in parameters:
     #       f.write('minimize %s\n' % parameters['minimize'])
     #   if 'run' in parameters:
     #       f.write('run %s\n' % parameters['run'])
     #   if not (('minimize' in parameters) or ('run' in parameters)):
     #       f.write('run 0\n')
     #   if 'dump' in parameters:
     #       f.write('dump %s\n' % parameters['dump'])
     #   else:
     #       f.write('dump dump_all all custom 1 %s id type x y z vx vy vz fx fy fz\n' % lammps_trj)            
     #   f.write('print __end_of_ase_invoked_calculation__\n')
     #   f.write('log /dev/stdout\n')
        if 'fix' in parameters:
            if parameters['fix']:
                for i in parameters['fix']:
                    f1.write('fix %s\n' % i)
        f.close()

    def as_dict(self):
        d = dict(structure=self.structure.as_dict(),
                 parameters=self.parameters, label=self.label,
                 specorder=self.specorder,
                 always_triclinic=self.always_triclinic,
                 no_data_file=self.no_data_file)
        d["@module"] = self.__class__.__module__
        d["@class"] = self.__class__.__name__
        return d
        
    @classmethod
    def from_dict(cls, d):
        structure = Structure.from_dict(d["structure"])
        return MPINTLammps(structure, parameters=d["parameters"],
                           label=d["label"],
                           specorder=d["specorder"],
                           always_triclinic=d["always_triclinic"],
                           no_data_file=d["no_data_file"])
Beispiel #4
0
class MPINTLammps(LAMMPS, PMGSONable):
    """
    setup LAMMPS for given structure and parameters
    extends ase.calculators.lammpsrun.LAMMPS
    """
    def __init__(self, structure, parameters={},
                 label='mpintlmp', specorder=None,
                 always_triclinic=False, no_data_file=False):
        LAMMPS.__init__(self, label=label,
                        parameters=parameters,
                        specorder=specorder, files=[],
                        always_triclinic=always_triclinic,
                        no_data_file=no_data_file)        
        self.structure = structure
        self.atoms = AseAtomsAdaptor().get_atoms(structure)
        self.label = label
        self.parameters = parameters
        self.specorder = specorder
        self.always_triclinic = always_triclinic
        self.no_data_file = no_data_file
        self.charges = None
        if 'charges' in self.parameters:
            self.charges = self.parameters['charges']
        
    def write_lammps_data(self, f):
        """
        write lammps structure data
        from ase with custom modifications
        """
        f.write(f.name + ' (written by mpinterfaces) \n\n')
        symbols = self.atoms.get_chemical_symbols()
        n_atoms = len(symbols)
        f.write('%d \t atoms \n' % n_atoms)
        if self.specorder is None:
            species = [tos.symbol
                       for tos in self.structure.types_of_specie]
        else:
            species = self.specorder
        n_atom_types = len(species)
        f.write('%d  atom types\n' % n_atom_types)
        p = prism(self.atoms.get_cell())
        xhi, yhi, zhi, xy, xz, yz = p.get_lammps_prism_str()
        f.write('0.0 %s  xlo xhi\n' % xhi)
        f.write('0.0 %s  ylo yhi\n' % yhi)
        f.write('0.0 %s  zlo zhi\n' % zhi)
        if self.always_triclinic or p.is_skewed():
            f.write('%s %s %s  xy xz yz\n' % (xy, xz, yz))
        f.write('\n\n')
        f.write('Atoms \n\n')
        for i, r in enumerate(map(p.pos_to_lammps_str,
                                  self.atoms.get_positions())):
            c = 0.0
            if self.charges:
                c = self.charges[symbols[i]]
            s = species.index(symbols[i]) + 1
            if 'atom_style' in self.parameters:
                if self.parameters['atom_style'] == 'charge':
                    
                    f.write('%6d %3d %6f %s %s %s\n' %
                            ((i+1, s, c)+tuple(r)) )
                else:
                    f.write('%6d %3d %s %s %s\n' % ((i+1, s)+tuple(r)))
        if self.atoms.get_velocities() is not None:
            f.write('\n\nVelocities \n\n')
            for i, v in enumerate(self.atoms.get_velocities()):
                f.write('%6d %s %s %s\n' % ((i+1,)+tuple(v)))
        f.close()

    def write_lammps_in(self, lammps_in=None, lammps_trj=None,
                        lammps_data=None):
        """
        write lammps input file
        from ase with custom modifications
        """        
        f = lammps_in
        f.write('clear\n' +
                ('variable dump_file string "%s"\n' % lammps_trj) +
                ('variable data_file string "%s"\n' % lammps_data))
        parameters = self.parameters
        pbc = self.atoms.get_pbc()
        f.write('units metal \n')
        if 'atom_style' in parameters:
            f.write('atom_style %s \n' % parameters['atom_style'])
        else:
            f.write('atom_style atomic \n')
        if 'boundary' in parameters:
            f.write('boundary %s \n' % parameters['boundary'])
        else:
            f.write('boundary %c %c %c \n' %
                    tuple('sp'[x] for x in pbc))
        f.write('atom_modify sort 0 0.0 \n')
        for key in ('neighbor' ,'newton'):
            if key in parameters:
                f.write('%s %s \n' % (key, parameters[key]))
        f.write('\n')
        # If no_data_file,
        # write the simulation box and the atoms
        if self.no_data_file:
            p = self.prism
            f.write('lattice sc 1.0\n')
            xhi, yhi, zhi, xy, xz, yz = p.get_lammps_prism_str()
            if self.always_triclinic or p.is_skewed():
                f.write('region asecell prism 0.0 %s 0.0 %s 0.0 %s ' %
                        (xhi, yhi, zhi))
                f.write('%s %s %s side in units box\n' % (xy, xz, yz))
            else:
                f.write(('region asecell block 0.0 %s 0.0 %s 0.0 %s '
                         'side in units box\n') % (xhi, yhi, zhi))
            symbols = self.atoms.get_chemical_symbols()
            if self.specorder is None:
                species = [tos.symbol for tos in self.structure.types_of_specie]
            else:
                species = self.specorder
            n_atom_types = len(species)
            species_i = dict([(s,i+1) for i,s in enumerate(species)])
            f.write('create_box %i asecell\n' % n_atom_types)
            for s, pos in zip(symbols, self.atoms.get_positions()):
                f.write('create_atoms %i single %s %s %s units box\n'%
                        ((species_i[s],)+p.pos_to_lammps_fold_str(pos)))
        else:
            f.write('read_data %s\n' % lammps_data)
        # interaction
        f.write('\n### interactions \n')
        if ( ('pair_style' in parameters) and ('pair_coeff' in parameters) ):
            pair_style = parameters['pair_style']
            f.write('pair_style %s \n' % pair_style)
            for pair_coeff in parameters['pair_coeff']:
                f.write('pair_coeff %s \n' % pair_coeff)
            if 'mass' in parameters:
                for mass in parameters['mass']:
                    f.write('mass %s \n' % mass)
        else:
            # default interaction
            f.write('pair_style lj/cut 2.5 \n' +
                    'pair_coeff * * 1 1 \n' +
                    'mass * 1.0 \n')
        f.write('\n### run\n')
        if 'fix' in parameters:
            if parameters['fix']:
                for i in parameters['fix']:
                    f.write('fix %s\n' % i)
        else:
            f.write('fix fix_nve all nve\n')
        if 'thermo_style' in parameters:
            f.write('thermo_style %s\n' % parameters['thermo_style'])
        else:
            f.write(('thermo_style custom %s\n') %
                    (' '.join(self._custom_thermo_args)))
        if 'thermo_modify' in parameters:
            f.write('thermo_modify %s\n' % parameters['thermo_modify'])
        else:
            f.write('thermo_modify flush yes\n')
        if 'thermo' in parameters:
            f.write('thermo %s\n' % parameters['thermo'])
        else:
            f.write('thermo 1\n')            
        if 'minimize' in parameters:
            f.write('minimize %s\n' % parameters['minimize'])
        if 'run' in parameters:
            f.write('run %s\n' % parameters['run'])
        if not (('minimize' in parameters) or ('run' in parameters)):
            f.write('run 0\n')
        if 'dump' in parameters:
            f.write('dump %s\n' % parameters['dump'])
        else:
            f.write('dump dump_all all custom 1 %s id type x y z vx vy vz fx fy fz\n' % lammps_trj)            
        f.write('print __end_of_ase_invoked_calculation__\n')
        f.write('log /dev/stdout\n') # Force LAMMPS to flush log
        f.close()

    def as_dict(self):
        d = dict(structure=self.structure.as_dict(),
                 parameters=self.parameters, label=self.label,
                 specorder=self.specorder,
                 always_triclinic=self.always_triclinic,
                 no_data_file=self.no_data_file)
        d["@module"] = self.__class__.__module__
        d["@class"] = self.__class__.__name__
        return d
        
    @classmethod
    def from_dict(cls, d):
        structure = Structure.from_dict(d["structure"])
        return MPINTLammps(structure, parameters=d["parameters"],
                           label=d["label"],
                           specorder=d["specorder"],
                           always_triclinic=d["always_triclinic"],
                           no_data_file=d["no_data_file"])
Beispiel #5
0
class MPINTLammps(LAMMPS, MSONable):
    """
    setup LAMMPS for given structure and parameters
    extends ase.calculators.lammpsrun.LAMMPS
    """
    def __init__(self,
                 structure,
                 parameters={},
                 label='mpintlmp',
                 specorder=None,
                 always_triclinic=False,
                 no_data_file=False):
        LAMMPS.__init__(self,
                        label=label,
                        parameters=parameters,
                        specorder=specorder,
                        files=[],
                        always_triclinic=always_triclinic,
                        no_data_file=no_data_file)
        self.structure = structure
        self.atoms = AseAtomsAdaptor().get_atoms(structure)
        self.label = label
        self.parameters = parameters
        self.specorder = specorder
        self.always_triclinic = always_triclinic
        self.no_data_file = no_data_file
        self.charges = None
        if 'charges' in self.parameters:
            self.charges = self.parameters['charges']

    def write_lammps_data(self, f):
        """
        write lammps structure data
        from ase with custom modifications
        """
        f.write(f.name + ' (written by mpinterfaces) \n\n')
        symbols = self.atoms.get_chemical_symbols()
        n_atoms = len(symbols)
        f.write('%d \t atoms \n' % n_atoms)
        if self.specorder is None:
            species = [tos.symbol for tos in self.structure.types_of_specie]
        else:
            species = self.specorder
        n_atom_types = len(species)
        f.write('%d  atom types\n' % n_atom_types)
        p = prism(self.atoms.get_cell())
        xhi, yhi, zhi, xy, xz, yz = p.get_lammps_prism_str()
        f.write('0.0 %s  xlo xhi\n' % xhi)
        f.write('0.0 %s  ylo yhi\n' % yhi)
        f.write('0.0 %s  zlo zhi\n' % zhi)
        if self.always_triclinic or p.is_skewed():
            f.write('%s %s %s  xy xz yz\n' % (xy, xz, yz))
        f.write('\n\n')
        f.write('Atoms \n\n')
        for i, r in enumerate(
                map(p.pos_to_lammps_str, self.atoms.get_positions())):
            c = 0.0
            if self.charges:
                c = self.charges[symbols[i]]
            s = species.index(symbols[i]) + 1
            if 'atom_style' in self.parameters:
                if self.parameters['atom_style'] == 'charge':

                    f.write('%6d %3d %6f %s %s %s\n' %
                            ((i + 1, s, c) + tuple(r)))
                else:
                    f.write('%6d %3d %s %s %s\n' % ((i + 1, s) + tuple(r)))
        if self.atoms.get_velocities() is not None:
            f.write('\n\nVelocities \n\n')
            for i, v in enumerate(self.atoms.get_velocities()):
                f.write('%6d %s %s %s\n' % ((i + 1, ) + tuple(v)))
        f.close()

    def write_lammps_in(self,
                        lammps_in=None,
                        lammps_trj=None,
                        lammps_data=None):
        """
        write lammps input file
        from ase with custom modifications
        """
        f = lammps_in
        f.write('clear\n' + ('variable dump_file string "%s"\n' % lammps_trj) +
                ('variable data_file string "%s"\n' % lammps_data))
        parameters = self.parameters
        pbc = self.atoms.get_pbc()
        f.write('units metal \n')
        if 'atom_style' in parameters:
            f.write('atom_style %s \n' % parameters['atom_style'])
        else:
            f.write('atom_style atomic \n')
        if 'boundary' in parameters:
            f.write('boundary %s \n' % parameters['boundary'])
        else:
            f.write('boundary %c %c %c \n' % tuple('sp'[x] for x in pbc))
        f.write('atom_modify sort 0 0.0 \n')
        for key in ('neighbor', 'newton'):
            if key in parameters:
                f.write('%s %s \n' % (key, parameters[key]))
        f.write('\n')
        # If no_data_file,
        # write the simulation box and the atoms
        if self.no_data_file:
            p = self.prism
            f.write('lattice sc 1.0\n')
            xhi, yhi, zhi, xy, xz, yz = p.get_lammps_prism_str()
            if self.always_triclinic or p.is_skewed():
                f.write('region asecell prism 0.0 %s 0.0 %s 0.0 %s ' %
                        (xhi, yhi, zhi))
                f.write('%s %s %s side in units box\n' % (xy, xz, yz))
            else:
                f.write(('region asecell block 0.0 %s 0.0 %s 0.0 %s '
                         'side in units box\n') % (xhi, yhi, zhi))
            symbols = self.atoms.get_chemical_symbols()
            if self.specorder is None:
                species = [
                    tos.symbol for tos in self.structure.types_of_specie
                ]
            else:
                species = self.specorder
            n_atom_types = len(species)
            species_i = dict([(s, i + 1) for i, s in enumerate(species)])
            f.write('create_box %i asecell\n' % n_atom_types)
            for s, pos in zip(symbols, self.atoms.get_positions()):
                f.write('create_atoms %i single %s %s %s units box\n' %
                        ((species_i[s], ) + p.pos_to_lammps_fold_str(pos)))
        else:
            f.write('read_data %s\n' % lammps_data)
        # interaction
        f.write('\n### interactions \n')
        if (('pair_style' in parameters) and ('pair_coeff' in parameters)):
            pair_style = parameters['pair_style']
            f.write('pair_style %s \n' % pair_style)
            for pair_coeff in parameters['pair_coeff']:
                f.write('pair_coeff %s \n' % pair_coeff)
            if 'mass' in parameters:
                for mass in parameters['mass']:
                    f.write('mass %s \n' % mass)
        else:
            # default interaction
            f.write('pair_style lj/cut 2.5 \n' + 'pair_coeff * * 1 1 \n' +
                    'mass * 1.0 \n')
        f.write('\n### run\n')
        if 'fix' in parameters:
            if parameters['fix']:
                for i in parameters['fix']:
                    f.write('fix %s\n' % i)
        else:
            f.write('fix fix_nve all nve\n')
        if 'thermo_style' in parameters:
            f.write('thermo_style %s\n' % parameters['thermo_style'])
        else:
            f.write(('thermo_style custom %s\n') %
                    (' '.join(self._custom_thermo_args)))
        if 'thermo_modify' in parameters:
            f.write('thermo_modify %s\n' % parameters['thermo_modify'])
        else:
            f.write('thermo_modify flush yes\n')
        if 'thermo' in parameters:
            f.write('thermo %s\n' % parameters['thermo'])
        else:
            f.write('thermo 1\n')
        if 'minimize' in parameters:
            f.write('minimize %s\n' % parameters['minimize'])
        if 'run' in parameters:
            f.write('run %s\n' % parameters['run'])
        if not (('minimize' in parameters) or ('run' in parameters)):
            f.write('run 0\n')
        if 'dump' in parameters:
            f.write('dump %s\n' % parameters['dump'])
        else:
            f.write(
                'dump dump_all all custom 1 %s id type x y z vx vy vz fx fy fz\n'
                % lammps_trj)
        f.write('print __end_of_ase_invoked_calculation__\n')
        f.write('log /dev/stdout\n')
        f.close()

    def as_dict(self):
        d = dict(structure=self.structure.as_dict(),
                 parameters=self.parameters,
                 label=self.label,
                 specorder=self.specorder,
                 always_triclinic=self.always_triclinic,
                 no_data_file=self.no_data_file)
        d["@module"] = self.__class__.__module__
        d["@class"] = self.__class__.__name__
        return d

    @classmethod
    def from_dict(cls, d):
        structure = Structure.from_dict(d["structure"])
        return MPINTLammps(structure,
                           parameters=d["parameters"],
                           label=d["label"],
                           specorder=d["specorder"],
                           always_triclinic=d["always_triclinic"],
                           no_data_file=d["no_data_file"])
Beispiel #6
0
def write_lammps_in( structure=None,lammps_in=None,lammps_in1=None,lammps_in2=None, lammps_trj=None,
                        lammps_data=None,parameters={}):
        """
        write lammps input file
        from ase with custom modifications
        """     
        structure.sort()   
        f = open(lammps_in,"w")
        f1 = open(lammps_in1,"w") #potential.mod
        f2 = open(lammps_in2,"w")
        f.write(('variable dump_file string "%s"\n' % lammps_trj) +
        ('variable up  equal 1.0e-6\n' )+
        ('variable cfac  equal 1.0e-4\n' )+
        ('variable cunits  string GPa\n' )+
        ('variable etol  equal 0\n' )+
        ('variable ftol  equal 1.0e-10\n' )+
        ('variable maxiter equal 1000\n' )+
        ('variable maxeval equal 10000\n' )+
        ('variable dmax equal 1.0e-2\n' )+
        ('variable data_file string "%s"\n' % "data"))
        atoms = AseAtomsAdaptor().get_atoms(structure)
        pbc = atoms.get_pbc()
        if 'control_file' in parameters:
            f2.write('include %s \n'%  parameters['control_file'])
        if 'units' in parameters:
            f.write('units %s \n' % parameters['units'])
        else:
            f.write('units metal \n')
        if 'atom_style' in parameters:
            f.write('atom_style %s \n' % parameters['atom_style'])
        else:
            f.write('atom_style atomic \n')
        if 'boundary' in parameters:
            f.write('boundary %s \n' % parameters['boundary'])
        else:
            f.write('boundary %c %c %c \n' %
                    tuple('sp'[x] for x in pbc))
        f.write('atom_modify sort 0 0.0 \n')
        for key in ('neighbor' ,'newton'):
            if key in parameters:
                f.write('%s %s \n' % (key, parameters[key]))
        f.write('\n')
        species = [tos for tos in Poscar(structure).site_symbols]
        n_atom_types = len(species)
        species_i = dict([(s,i+1) for i,s in enumerate(species)])
        f.write('read_data %s\n' % "data")
        f.write('\n### interactions \n')
        if ( 'lib' in parameters ):
            lib = parameters['lib']
            f1.write('%s \n' % lib)
        if ( ('pair_style' in parameters) and ('pair_coeff' in parameters) ):
            pair_style = parameters['pair_style']
            f1.write('pair_style %s \n' % pair_style)
            symbols = atoms.get_chemical_symbols()
            #print "site symbolss",Poscar(structure).site_symbols
            species = [tos for tos in Poscar(structure).site_symbols]
            if parameters['pair_style']=='rebomos':
                
                species = [tos.replace("Mo","M") for tos in Poscar(structure).site_symbols]
            tag=''
            for i in species:
                tag=tag+' '+i
            pair_coef =  '* * '+str(parameters['pair_coeff'])+' '+tag
            f1.write('pair_coeff %s \n' % pair_coef)

        

            masses=[]
            for m in  atoms.get_masses():
                if m not in masses:
                   masses.append(m)
            count=0
            for i in masses:
                count=count+1
                f.write('mass'+' '+str(count)+' '+str(i)+'\n')
        else:
            f.write('pair_style lj/cut 2.5 \n' +
                    'pair_coeff * * 1 1 \n' +
                    'mass * 1.0 \n')
        f1.write('neighbor 1.0 nsq\n' )
        f1.write('neigh_modify once no every 1 delay 0 check yes\n' )
        if 'min' not in parameters: 
              f1.write('min_style  cg\n' )
              f1.write('min_modify           dmax ${dmax} line quadratic\n' )
        f1.write('thermo          1\n' )
        f1.write('thermo_style custom step temp press cpu pxx pyy pzz pxy pxz pyz ke pe etotal vol lx ly lz atoms\n' )
        f1.write('thermo_modify norm no\n' )
        if 'fix' in parameters:
            if parameters['fix']:
                for i in parameters['fix']:
                    f1.write('fix %s\n' % i)
        f.close()
        f1.close()
        f2.close()