def test_loaded(self):
		file_path = Path.clean(self.data_path, "incar_1")
		incar = Incar(file_path)

		self.assertEqual(incar.lines, ['', 'Comment here #messy messy', 'ALGO = Fast #stuff here', 'whats up', '', '', 'EDIFF = 0.00075', 'ENCUT = 520', 'IBRION = 2', 'ICHARG = 1', 'ISIF = 3', 'ISMEAR = -5', 'ISPIN = 2', 'LORBIT = 11 #comment with equals sign', '', '', '', 'LREAL = Auto', 'LWAVE = False', 'MAGMOM = 15*0.6', 'NELM = 100', 'NSW = 99', 'PREC = Accurate', '', '#lonely sigma with equals signequalsequals!', '', 'X = y #equalsequals', 'f   #equals', 'SIGMA = 0.05'])
		self.assertEqual(incar.dict.items(), [('ALGO', 'Fast'), ('EDIFF', '0.00075'), ('ENCUT', '520'), ('IBRION', '2'), ('ICHARG', '1'), ('ISIF', '3'), ('ISMEAR', '-5'), ('ISPIN', '2'), ('LORBIT', '11'), ('LREAL', 'Auto'), ('LWAVE', 'False'), ('MAGMOM', '15*0.6'), ('NELM', '100'), ('NSW', '99'), ('PREC', 'Accurate'), ('X', 'y'), ('SIGMA', '0.05')])

		
	def get_external_relaxation_incar(custom_parameters_dictionary=None):
		incar = Incar()

		#optional parameters that can be overwritten by the user
		incar['ibrion'] = 2
		incar['nsw'] = 151
		incar['nelmin'] = 6 #helps with force accuracy
		incar['isif'] = 3 #by default, calculate the stress tensor (atoms won't move still)
		incar['ismear'] = 0
		incar['sigma'] = 0.02
		incar['prec'] = 'Accurate'
		incar['ediff'] = 1.0e-6
		incar['encut'] = 600
		incar['lwave'] = True
		incar['lasph'] = True
		# incar['lcharg'] = False

		incar.modify_from_dictionary(custom_parameters_dictionary)

		return incar
Beispiel #3
0
	def incar(self):
		incar_path = Path.clean(self.path, 'INCAR')
		if Path.exists(incar_path):
			return Incar(incar_path)
		else:
			return None
Beispiel #4
0
    def __init__(self, vasp_calculation_input_dictionary):

        vasp_calculation_input_dictionary = copy.deepcopy(
            vasp_calculation_input_dictionary)

        vasp_calculation_input_dictionary = {
            k.lower(): v
            for k, v in vasp_calculation_input_dictionary.items()
        }  #enforce all keys lowercase

        path = Path.clean(vasp_calculation_input_dictionary.pop('path'))

        information_structure = None  #used for number of nodes and potcar
        if isinstance(vasp_calculation_input_dictionary['structure'],
                      Structure):
            initial_structure = vasp_calculation_input_dictionary.pop(
                'structure')
            information_structure = initial_structure
            contcar_path = None
        else:
            initial_structure = None
            contcar_path = vasp_calculation_input_dictionary.pop('structure')
            information_structure = Structure(contcar_path)

        wavecar_path = vasp_calculation_input_dictionary.pop(
            'wavecar_path'
        ) if 'wavecar_path' in vasp_calculation_input_dictionary else None
        chargecar_path = vasp_calculation_input_dictionary.pop(
            'chargecar_path'
        ) if 'chargecar_path' in vasp_calculation_input_dictionary else None
        incar_template = vasp_calculation_input_dictionary.pop(
            'incar_template'
        ) if 'incar_template' in vasp_calculation_input_dictionary else None
        kpoints_scheme = vasp_calculation_input_dictionary.pop(
            'kpoints_scheme'
        ) if 'kpoints_scheme' in vasp_calculation_input_dictionary else None
        kpoints_list = [
            int(x) for x in vasp_calculation_input_dictionary.pop(
                'kpoints_list').split(' ')
        ] if ('kpoints_list' in vasp_calculation_input_dictionary
              and vasp_calculation_input_dictionary['kpoints_list'] != None
              ) else None
        potcar_type = vasp_calculation_input_dictionary.pop(
            'potcar_type'
        ) if 'potcar_type' in vasp_calculation_input_dictionary else 'lda_paw'
        vasp_code_type = vasp_calculation_input_dictionary.pop(
            'vasp_code_type'
        ) if 'vasp_code_type' in vasp_calculation_input_dictionary else 'standard'
        node_count = vasp_calculation_input_dictionary.pop(
            'node_count'
        ) if 'node_count' in vasp_calculation_input_dictionary else None
        use_mp_hubbard_u = vasp_calculation_input_dictionary.pop(
            'use_mp_hubbard_u'
        ) if 'use_mp_hubbard_u' in vasp_calculation_input_dictionary else None

        for file_path in [wavecar_path, chargecar_path]:
            if file_path != None and not Path.exists(file_path):
                print "Warning: Path " + str(
                    file_path) + " specified does not exist. Not using."
                #raise Exception("Path " + str(file_path) + " specified does not exist.")

        if kpoints_scheme != None and kpoints_list != None:
            kpoints = Kpoints(scheme_string=kpoints_scheme,
                              subdivisions_list=kpoints_list)

            if 'kspacing' in vasp_calculation_input_dictionary:
                raise Exception(
                    "kpoints are being specified by more than one method.")
        elif 'kspacing' not in vasp_calculation_input_dictionary:
            raise Exception(
                "If kpoints aren't explicitly defined through a scheme and a list, the kspacing tag must be present in the incar."
            )
        else:
            kpoints = None

        potcar = Potcar(elements_list=information_structure.get_species_list(),
                        calculation_type=potcar_type)

        submission_script_file = QueueAdapter.get_submission_file()

        if os.environ['QUEUE_ADAPTER_HOST'] != 'Savio':
            if node_count == None:
                submission_script_file = QueueAdapter.modify_number_of_cores_from_num_atoms(
                    submission_script_file, information_structure.site_count)
            else:
                submission_script_file = QueueAdapter.set_number_of_nodes(
                    submission_script_file, node_count)

            submission_script_file = QueueAdapter.modify_submission_script(
                submission_script_file, modification_key=vasp_code_type)

        incar_modifiers = vasp_calculation_input_dictionary  #whatever is left should only be incar modifiers - we popped all other keys

        for key, value in incar_modifiers.items(
        ):  #make sure there are no None values - these should not be put in INCAR
            if value in [None, 'None']:
                del incar_modifiers[key]

        if 'encut' in incar_modifiers and (
                0.1 < incar_modifiers['encut']) and (
                    incar_modifiers['encut'] <
                    10.0):  #Should use this as a multiplier times enmax
            enmax = potcar.get_enmax()

            incar_modifiers['encut'] = int(incar_modifiers['encut'] * enmax)

        if incar_template == 'static':
            incar = IncarMaker.get_static_incar(
                custom_parameters_dictionary=incar_modifiers)
        elif incar_template == 'external_relaxation':
            incar = IncarMaker.get_external_relaxation_incar(
                custom_parameters_dictionary=incar_modifiers)
        elif incar_template != None:
            raise Exception("Incar template " + str(incar_template) +
                            " not valid")
        else:
            incar = Incar()
            incar.modify_from_dictionary(incar_modifiers)

        if 'lreal' not in incar:
            if information_structure.site_count > 20:
                incar['lreal'] = 'Auto'
            else:
                incar['lreal'] = False

        if 'npar' not in incar:
            if os.environ['QUEUE_ADAPTER_HOST'] == 'Savio':
                incar['npar'] = 4
            else:
                incar['npar'] = QueueAdapter.get_optimal_npar(
                    submission_script_file)
        elif incar['npar'] in ['Remove', 'remove']:
            del incar['npar']

        ###################TEMPORARILY HARDCODED FOR PEROVSKITES##########################################
        if use_mp_hubbard_u:
            u_species = initial_structure.get_species_list()[1]
            mp_hubbard_u_values = {
                'Co': 3.32,
                'Cr': 3.7,
                'Fe': 5.3,
                'Mn': 3.9,
                'Mo': 4.38,
                'Ni': 6.2,
                'V': 3.25,
                'W': 6.2
            }

            if u_species in mp_hubbard_u_values.keys():

                u_value = mp_hubbard_u_values[u_species]

                incar['LDAU'] = True
                incar['LDAUJ'] = '0 0 0'
                incar['LDAUL'] = '0 2 0'
                incar['LDAUPRINT'] = 1
                incar['LDAUTYPE'] = 2
                incar['LDAUU'] = '0 ' + str(u_value) + ' 0'
                incar['LMAXMIX'] = 4
                incar['LORBIT'] = 11

        super(VaspCalculationGenerator,
              self).__init__(path=path,
                             initial_structure=initial_structure,
                             incar=incar,
                             kpoints=kpoints,
                             potcar=potcar,
                             submission_script_file=submission_script_file,
                             contcar_path=contcar_path,
                             wavecar_path=wavecar_path,
                             chargecar_path=chargecar_path)
	def test_init(self):
		file_path = Path.clean(self.data_path, "empty_incar")

		incar = Incar(file_path)
		self.assertEqual(incar.dict, {})
		self.assertEqual(incar.lines, [])

		incar[0] = "This is a comment"
		self.assertEqual(incar.dict, {})
		self.assertEqual(incar.lines, ["This is a comment"])

		incar['algo'] = 'Fast'
		self.assertEqual(incar.dict.items(), [('ALGO', 'Fast')])
		self.assertEqual(incar.lines, ['This is a comment', 'ALGO = Fast'])

		incar['ALGO'] = 'Fast'
		self.assertEqual(incar.dict.items(), [('ALGO', 'Fast')])
		self.assertEqual(incar.lines, ['This is a comment', 'ALGO = Fast'])

		incar['      ALgo  '] = 'Medium'
		self.assertEqual(incar.dict.items(), [('ALGO', 'Medium')])
		self.assertEqual(incar.lines, ['This is a comment', 'ALGO = Medium'])

		incar['NSW'] = 191
		incar += "Here is another comment"
		incar['nsw'] = '181'

		self.assertEqual(incar.dict.items(), [('ALGO', 'Medium'), ('NSW', '181')])
		self.assertEqual(incar.lines, ['This is a comment', 'ALGO = Medium', 'NSW = 181', 'Here is another comment'])

		incar[0] = "Comment revised"
		incar[1] = "   Algo =   Fast"

		self.assertEqual(incar.dict.items(), [('ALGO', 'Fast'), ('NSW', '181')])
		self.assertEqual(str(incar), 'Comment revised\nALGO = Fast\nNSW = 181\nHere is another comment\n')

		incar[2] += " #here is a comment"
		incar += "#and another"
		incar += "one more comment."

		self.assertEqual(incar.dict.items(), [('ALGO', 'Fast'), ('NSW', '181')])
		self.assertEqual(incar.lines, ['Comment revised', 'ALGO = Fast', 'NSW = 181 #here is a comment', 'Here is another comment', '#and another', 'one more comment.'])
		self.assertEqual(str(incar), 'Comment revised\nALGO = Fast\nNSW = 181 #here is a comment\nHere is another comment\n#and another\none more comment.\n')

		incar['isif'] = 3

		del incar['  ALgO']
		del incar['ALGo ']
		incar['algo'] = 'Slow'
		del incar['ALGO']
		incar['prec'] = 'accurate'
		incar['ediff'] = 0.000001

		self.assertEqual(incar.dict.items(), [('NSW', '181'), ('ISIF', '3'), ('PREC', 'accurate'), ('EDIFF', '1e-06')])
		self.assertEqual(incar.lines, ['Comment revised', 'NSW = 181 #here is a comment', 'Here is another comment', '#and another', 'one more comment.', 'ISIF = 3', 'PREC = accurate', 'EDIFF = 1e-06'])
		self.assertEqual(str(incar), 'Comment revised\nNSW = 181 #here is a comment\nHere is another comment\n#and another\none more comment.\nISIF = 3\nPREC = accurate\nEDIFF = 1e-06\n')
		self.assertEqual(float(incar['ediff']), 0.000001)
		self.assertEqual(incar['prec'], 'accurate')

		file_out_path = Path.clean(self.data_path, "test_made_incar")
		incar.write_to_path(file_out_path)

		incar = Incar(file_out_path)
		self.assertEqual(incar['prec'], 'accurate')
		self.assertEqual(str(incar), 'Comment revised\nNSW = 181 #here is a comment\nHere is another comment\n#and another\none more comment.\nISIF = 3\nPREC = accurate\nEDIFF = 1e-06\n')

		incar[0] = '    Comment revised   ' #should kill this whitespace
		self.assertEqual(str(incar), 'Comment revised\nNSW = 181 #here is a comment\nHere is another comment\n#and another\none more comment.\nISIF = 3\nPREC = accurate\nEDIFF = 1e-06\n')

		with self.assertRaises(Exception):
			incar['proper ty'] = 'value'

		with self.assertRaises(Exception):
			incar += 'PREC = repeat'