def __init__(self, name, source_dir='.', mag_atoms=None, magmom_magnitude=2.0, distance_tolerance=0.1,
                 incar_extra=None, debug=False):
        """
        This class provides a population of Magnetic Moment vectors for the same structure and was created to be used
        on VASP.
        The magnetic moment is set in cartesian coordinates with 3 numbers for each atom in the unit cell.
        This population provides methods to manipulate the magnetic moments between different candidates in order to
        optimize the magnetic orientations using the global-search methods implemented on PyChemia.

        :param name: The name of the database to be created or directly the PyChemiaDB database object.
                     The name is used when the database can be created without username, password and no encryption.
                     Otherwise the database must be created first and its object be 'name' argument.
        :param source_dir: Directory that contains the basic 4 files for VASP: 'POSCAR', 'POTCAR', 'KPOINTS' and 'INCAR'
                            Except for 'INCAR' the files are linked symbolically on each directory that will run VASP
                            The input variables on 'INCAR' changing only MAGMOM and I_CONSTRAINED_M.
                            The 'INCAR' file could contain generic variables and some other variables could be directly
                            specified using the dictionary 'incar_extra'.
        :param mag_atoms: List of atoms for which the Magnetic Moments are changed. If the variable is None, the list
                            is inferred from the original INCAR file. The numbering of atoms start with 0.
        :param magmom_magnitude: Fix value for the magnitude of the magnetic moment imposed for all the atoms in
                                'mag_atoms' list
        :param distance_tolerance: Maximal distance in magnetic moments to consider two candidates as equivalent.
        :param incar_extra: Extra variables for INCAR file that are added or replaced from the INCAR read with
                            'source_dir'
        :param debug: If True produce a verbose output during the different calls to the methods.
        """
        Population.__init__(self, name, 'global', distance_tolerance=distance_tolerance)
        if not os.path.isfile(source_dir + os.sep + 'INCAR'):
            raise ValueError("INCAR not found")
        if not os.path.isfile(source_dir + os.sep + 'POSCAR'):
            raise ValueError("POSCAR not found")
        if not os.path.isfile(source_dir + os.sep + 'POTCAR'):
            raise ValueError("POTCAR not found")
        if not os.path.isfile(source_dir + os.sep + 'KPOINTS'):
            raise ValueError("KPOINTS not found")
        self.input = read_incar(source_dir + os.sep + 'INCAR')
        self.source_dir = source_dir

        if 'MAGMOM' not in self.input:
            raise ValueError('INCAR should define the MAGMOM variable')
        magmom = np.array(self.input.MAGMOM).reshape((-1, 3))

        self.structure = read_poscar(source_dir + os.sep + 'POSCAR')
        if mag_atoms is None:
            self.mag_atoms = list(np.where(np.apply_along_axis(np.linalg.norm, 1, magmom) > 0.0)[0])
            self.mag_atoms = [int(x) for x in self.mag_atoms]
        else:
            self.mag_atoms = mag_atoms
        self.magmom_magnitude = magmom_magnitude
        if incar_extra is None:
            self.incar_extra = {'IBRION': -1,
                                'LWAVE': True,
                                'LAMBDA': 10,
                                'NSW': 0,
                                'I_CONSTRAINED_M': 1}

        else:
            self.incar_extra = incar_extra
        self.debug = debug
Exemplo n.º 2
0
    def __init__(self, name, source_dir='.', mag_atoms=None, magmom_magnitude=2.0, distance_tolerance=0.1):
        Population.__init__(self, name, 'global')
        if not os.path.isfile(source_dir + os.sep + 'INCAR'):
            raise ValueError("INCAR not found")
        if not os.path.isfile(source_dir + os.sep + 'POSCAR'):
            raise ValueError("POSCAR not found")
        self.input = read_incar(source_dir + os.sep + 'INCAR')
        magmom = np.array(self.input.get_value('MAGMOM')).reshape((-1, 3))

        self.structure = read_poscar(source_dir + os.sep + 'POSCAR')
        if mag_atoms is None:
            self.mag_atoms = list(np.where(np.apply_along_axis(np.linalg.norm, 1, magmom) > 0.0)[0])
            self.mag_atoms = [int(x) for x in self.mag_atoms]
        else:
            self.mag_atoms = mag_atoms
        self.magmom_magnitude = magmom_magnitude
        self.distance_tolerance = distance_tolerance
Exemplo n.º 3
0
 def prepare_folder(self, entry_id, workdir, binary='vasp', source_dir='.'):
     vj = VaspJob()
     structure = self.get_structure(entry_id)
     kp = KPoints.optimized_grid(structure.lattice, kp_density=2E4)
     vj.initialize(structure, workdir=workdir, kpoints=kp, binary=binary)
     vj.clean()
     vj.input_variables = read_incar(source_dir + '/INCAR')
     magmom_sph = self.get_entry(entry_id, {'properties.magmom': 1})['properties']['magmom']
     magmom_car = spherical_to_cartesian(magmom_sph)
     vj.input_variables.variables['MAGMOM'] = [float(x) for x in magmom_car.flatten()]
     vj.input_variables.variables['M_CONSTR'] = [float(x) for x in magmom_car.flatten()]
     vj.input_variables.variables['IBRION'] = -1
     vj.input_variables.variables['LWAVE'] = True
     vj.input_variables.variables['EDIFF'] = 1E-5
     vj.input_variables.variables['LAMBDA'] = 10
     vj.input_variables.variables['NSW'] = 0
     vj.input_variables.variables['I_CONSTRAINED_M'] = 1
     vj.set_inputs()
    def prepare_folder(self, entry_id, workdir, binary='vasp', source_dir='.'):

        if not os.path.isdir(workdir):
            os.mkdir(workdir)

        for i in ['KPOINTS', 'POSCAR', 'POTCAR']:
            if os.path.exists(workdir+os.sep+i):
                os.remove(workdir+os.sep+i)
            os.symlink(os.path.abspath(self.source_dir+os.sep+i), workdir+os.sep+i)

        incar = read_incar(self.source_dir + os.sep + 'INCAR')
        magmom_sph = self.get_entry(entry_id, {'properties.magmom': 1})['properties']['magmom']
        magmom_car = spherical_to_cartesian(magmom_sph)
        incar['MAGMOM'] = [float(x) for x in magmom_car.flatten()]
        incar['M_CONSTR'] = [float(x) for x in magmom_car.flatten()]
        for i in self.incar_extra:
            incar[i] = self.incar_extra[i]
        incar.write(workdir + os.sep + 'INCAR')
Exemplo n.º 5
0
    def prepare_folder(self, entry_id, workdir, binary='vasp', source_dir='.'):

        if not os.path.isdir(workdir):
            os.mkdir(workdir)

        for i in ['KPOINTS', 'POSCAR', 'POTCAR']:
            if os.path.exists(workdir + os.sep + i):
                os.remove(workdir + os.sep + i)
            os.symlink(os.path.abspath(self.source_dir + os.sep + i),
                       workdir + os.sep + i)

        input = read_incar(self.source_dir + os.sep + 'INCAR')
        magmom_sph = self.get_entry(
            entry_id, {'properties.magmom': 1})['properties']['magmom']
        magmom_car = spherical_to_cartesian(magmom_sph)
        input['MAGMOM'] = [float(x) for x in magmom_car.flatten()]
        input['M_CONSTR'] = [float(x) for x in magmom_car.flatten()]
        for i in self.incar_extra:
            input[i] = self.incar_extra[i]
        input.write(workdir + os.sep + 'INCAR')
Exemplo n.º 6
0
    def prepare_folder(self, entry_id, workdir, binary='vasp', source_dir='.'):

        if not os.path.isdir(workdir):
            os.mkdir(workdir)

        for i in ['KPOINTS', 'POSCAR', 'POTCAR']:
            if os.path.exists(workdir+os.sep+i):
                os.remove(workdir+os.sep+i)
            os.symlink(os.path.abspath(self.source_dir+os.sep+i), workdir+os.sep+i)

        input = read_incar(self.source_dir + os.sep + 'INCAR')
        magmom_sph = self.get_entry(entry_id, {'properties.magmom': 1})['properties']['magmom']
        magmom_car = spherical_to_cartesian(magmom_sph)
        input['MAGMOM'] = [float(x) for x in magmom_car.flatten()]
        input['M_CONSTR'] = [float(x) for x in magmom_car.flatten()]
        input['IBRION'] = -1
        input['LWAVE'] = True
        input['EDIFF'] = 1E-5
        input['LAMBDA'] = self.var_lambda
        input['NSW'] = 0
        input['I_CONSTRAINED_M'] = 1
        input.write(workdir + os.sep + 'INCAR')
Exemplo n.º 7
0
    def __init__(self,
                 name,
                 source_dir='.',
                 mag_atoms=None,
                 magmom_magnitude=2.0,
                 distance_tolerance=0.1,
                 incar_extra=None,
                 debug=False):
        """
        This class provides a population of Magnetic Moment vectors for the same structure and was created to be used
        on VASP.
        The magnetic moment is set in cartesian coordinates with 3 numbers for each atom in the unit cell.
        This population provides methods to manipulate the magnetic moments between different candidates in order to
        optimize the magnetic orientations using the global-search methods implemented on PyChemia.

        :param name: The name of the database to be created or directly the PyChemiaDB database object.
                     The name is used when the database can be created without username, password and no encryption.
                     Otherwise the database must be created first and its object be 'name' argument.
        :param source_dir: Directory that contains the basic 4 files for VASP: 'POSCAR', 'POTCAR', 'KPOINTS' and 'INCAR'
                            Except for 'INCAR' the files are linked symbolically on each directory that will run VASP
                            The input variables on 'INCAR' changing only MAGMOM and I_CONSTRAINED_M.
                            The 'INCAR' file could contain generic variables and some other variables could be directly
                            specified using the dictionary 'incar_extra'.
        :param mag_atoms: List of atoms for which the Magnetic Moments are changed. If the variable is None, the list
                            is inferred from the original INCAR file. The numbering of atoms start with 0.
        :param magmom_magnitude: Fix value for the magnitude of the magnetic moment imposed for all the atoms in
                                'mag_atoms' list
        :param distance_tolerance: Maximal distance in magnetic moments to consider two candidates as equivalent.
        :param incar_extra: Extra variables for INCAR file that are added or replaced from the INCAR read with
                            'source_dir'
        :param debug: If True produce a verbose output during the different calls to the methods.
        """
        Population.__init__(self,
                            name,
                            'global',
                            distance_tolerance=distance_tolerance)
        if not os.path.isfile(source_dir + os.sep + 'INCAR'):
            raise ValueError("INCAR not found")
        if not os.path.isfile(source_dir + os.sep + 'POSCAR'):
            raise ValueError("POSCAR not found")
        if not os.path.isfile(source_dir + os.sep + 'POTCAR'):
            raise ValueError("POTCAR not found")
        if not os.path.isfile(source_dir + os.sep + 'KPOINTS'):
            raise ValueError("KPOINTS not found")
        self.input = read_incar(source_dir + os.sep + 'INCAR')
        self.source_dir = source_dir

        if 'MAGMOM' not in self.input:
            raise ValueError('INCAR should define the MAGMOM variable')
        magmom = np.array(self.input.MAGMOM).reshape((-1, 3))

        self.structure = read_poscar(source_dir + os.sep + 'POSCAR')
        if mag_atoms is None:
            self.mag_atoms = list(
                np.where(
                    np.apply_along_axis(np.linalg.norm, 1, magmom) > 0.0)[0])
            self.mag_atoms = [int(x) for x in self.mag_atoms]
        else:
            self.mag_atoms = mag_atoms
        self.magmom_magnitude = magmom_magnitude
        if incar_extra is None:
            self.incar_extra = {
                'IBRION': -1,
                'LWAVE': True,
                'LAMBDA': 10,
                'NSW': 0,
                'I_CONSTRAINED_M': 1
            }

        else:
            self.incar_extra = incar_extra
        self.debug = debug