How to use the pymatgen.io.vasp.inputs.Poscar function in pymatgen

To help you get started, we’ve selected a few pymatgen examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github materialsproject / pymatgen / pymatgen / io / vasp / inputs.py View on Github external
predictor_corrector_preamble = (lines[0] + "\n" + lines[1]
                                                + "\n" + lines[2])
                # Rest is three sets of parameters, each set contains
                # x, y, z predictor-corrector parameters for every atom in orde
                lines = lines[3:]
                for st in range(nsites):
                    d1 = [float(tok) for tok in lines[st].split()]
                    d2 = [float(tok) for tok in lines[st+nsites].split()]
                    d3 = [float(tok) for tok in lines[st+2*nsites].split()]
                    predictor_corrector.append([d1,d2,d3])
        else:
            velocities = None
            predictor_corrector = None
            predictor_corrector_preamble = None

        return Poscar(struct, comment, selective_dynamics, vasp5_symbols,
                      velocities=velocities,
                      predictor_corrector=predictor_corrector,
                      predictor_corrector_preamble=predictor_corrector_preamble)
github kylebystrom / pawpyseed / pawpyseed / core / wavefunction.py View on Github external
"""
		Construct a Wavefunction object from file paths.

		Arguments:
			struct (str): VASP POSCAR or CONTCAR file path
			pwf (str): VASP WAVECAR file path
			cr (str): VASP POTCAR file path
			vr (str): VASP vasprun file path
			outcar (str): VASP OUTCAR file path

		Returns:
			Wavefunction object
		"""
		vr = Vasprun(vr)
		symprec = vr.parameters["SYMPREC"]
		return Wavefunction(Poscar.from_file(struct).structure,
			PseudoWavefunction(pwf, vr),
			CoreRegion(Potcar.from_file(cr)),
			Outcar(outcar), symprec, setup_projectors)
github materialsproject / pymatgen / pymatgen / command_line / aconvasp_caller.py View on Github external
def run_aconvasp_command(command, structure):
    """
    Helper function for calling aconvasp with different arguments
    """
    poscar = Poscar(structure)
    p = subprocess.Popen(command, stdout=subprocess.PIPE,
                         stdin=subprocess.PIPE,
                         stderr=subprocess.PIPE)
    output = p.communicate(input=poscar.get_string())
    return output
github materialsproject / pymatgen / pymatgen / io / vasp / outputs.py View on Github external
def write_file(self, file_name, vasp4_compatible=False):
        """
        Write the VolumetricData object to a vasp compatible file.

        Args:
            file_name (str): Path to a file
            vasp4_compatible (bool): True if the format is vasp4 compatible
        """

        with zopen(file_name, "wt") as f:
            p = Poscar(self.structure)

            lines = p.comment + "\n"
            lines += "   1.00000000000000\n"
            latt = self.structure.lattice.matrix
            lines += " %12.6f%12.6f%12.6f\n" % tuple(latt[0, :])
            lines += " %12.6f%12.6f%12.6f\n" % tuple(latt[1, :])
            lines += " %12.6f%12.6f%12.6f\n" % tuple(latt[2, :])
            if not vasp4_compatible:
                lines += "".join(["%5s" % s for s in p.site_symbols]) + "\n"
            lines += "".join(["%6d" % x for x in p.natoms]) + "\n"
            lines += "Direct\n"
            for site in self.structure:
                lines += "%10.6f%10.6f%10.6f\n" % tuple(site.frac_coords)
            lines += "\n"
            f.write(lines)
            a = self.dim
github materialsproject / pymatgen / pymatgen / command_line / enumlib_caller.py View on Github external
else:
                        site_properties[k] = [v]
            ordered_structure = Structure(
                original_latt,
                [site.species for site in self.ordered_sites],
                [site.frac_coords for site in self.ordered_sites],
                site_properties=site_properties
            )
            inv_org_latt = np.linalg.inv(original_latt.matrix)

        for file in glob.glob('vasp.*'):
            with open(file) as f:
                data = f.read()
                data = re.sub(r'scale factor', "1", data)
                data = re.sub(r'(\d+)-(\d+)', r'\1 -\2', data)
                poscar = Poscar.from_string(data, self.index_species)
                sub_structure = poscar.structure
                # Enumeration may have resulted in a super lattice. We need to
                # find the mapping from the new lattice to the old lattice, and
                # perform supercell construction if necessary.
                new_latt = sub_structure.lattice

                sites = []

                if len(self.ordered_sites) > 0:
                    transformation = np.dot(new_latt.matrix, inv_org_latt)
                    transformation = [[int(round(cell)) for cell in row]
                                      for row in transformation]
                    logger.debug("Supercell matrix: {}".format(transformation))
                    s = ordered_structure * transformation
                    sites.extend([site.to_unit_cell() for site in s])
                    super_latt = sites[-1].lattice
github henniggroup / MPInterfaces / mpinterfaces / calibrate.py View on Github external
def create_interface(self):
        """
        add params that you want to vary
        """
        structure = self.input_structure.copy()
        iface = sorted(Interface(structure,
                                 hkl=self.system['hkl'],
                                 ligand=Ligand.from_dict(
                                     self.system['ligand']),
                                 from_ase=self.from_ase))
        sd = self.set_sd_flags(iface, n_layers=2)
        # if there are other paramters that are being varied
        # change the comment accordingly
        comment = self.system['hkl'] + self.system['ligand']['name']
        return Poscar(iface, comment=comment,
                      selective_dynamics=sd)
github kylebystrom / pawpyseed / pawpyseed / core / wavefunction.py View on Github external
def _convert_to_vasp_volumetric(self, filename, dim):
		"""
		Utility function to convert pawpyseed volumetric
		output to VASP volumetric output.
		"""

		#from pymatgen VolumetricData class
		p = Poscar(self.structure)
		lines = filename + '\n'
		lines += "   1.00000000000000\n"
		latt = self.structure.lattice.matrix
		lines += " %12.6f%12.6f%12.6f\n" % tuple(latt[0, :])
		lines += " %12.6f%12.6f%12.6f\n" % tuple(latt[1, :])
		lines += " %12.6f%12.6f%12.6f\n" % tuple(latt[2, :])
		lines += "".join(["%5s" % s for s in p.site_symbols]) + "\n"
		lines += "".join(["%6d" % x for x in p.natoms]) + "\n"
		lines += "Direct\n"
		for site in self.structure:
			lines += "%10.6f%10.6f%10.6f\n" % tuple(site.frac_coords)
		lines += " \n"
	
		f = open(filename, 'r')
		nums = f.read()
		f.close()
github materialsproject / pymatgen / pymatgen / io / vasp / outputs.py View on Github external
def write_file(self, file_name, vasp4_compatible=False):
        """
        Write the VolumetricData object to a vasp compatible file.

        Args:
            file_name (str): Path to a file
            vasp4_compatible (bool): True if the format is vasp4 compatible
        """

        with zopen(file_name, "wt") as f:
            p = Poscar(self.structure)

            lines = p.comment + "\n"
            lines += "   1.00000000000000\n"
            latt = self.structure.lattice.matrix
            lines += " %12.6f%12.6f%12.6f\n" % tuple(latt[0, :])
            lines += " %12.6f%12.6f%12.6f\n" % tuple(latt[1, :])
            lines += " %12.6f%12.6f%12.6f\n" % tuple(latt[2, :])
            if not vasp4_compatible:
                lines += "".join(["%5s" % s for s in p.site_symbols]) + "\n"
            lines += "".join(["%6d" % x for x in p.natoms]) + "\n"
            lines += "Direct\n"
            for site in self.structure:
                lines += "%10.6f%10.6f%10.6f\n" % tuple(site.frac_coords)
            lines += "\n"
            f.write(lines)
            a = self.dim
github materialsproject / pymatgen / pymatgen / command_line / aconvasp_caller.py View on Github external
def get_prim_struct(structure):
    """
    Get standard primitive
    """
    output = run_aconvasp_command(["aconvasp", "--std_prim"], structure)
    if "ERROR" in output[1]:
        raise AconvaspError(output[1])
    tmp = Poscar.from_string(output[0])
    return {'struct': tmp.structure, 'comm': tmp.comment}
github henniggroup / MPInterfaces / examples / workflows / graphene_on_metal.py View on Github external
- creates required input files and submits the jobs to the que
    - 8 + 1 jobs
    - returns: step1_sub.json step1_2d.json 
    """
    #job directory for the runs
    job_dir_sub = 'step1_sub'
    job_dir_2d = 'step1_2d'
    # create list of all substrate poscars
    poscars_sub = []
    poscars_2d = []
    # substrate structures
    for sub in substrates:
        struct_sub = get_struct_from_mp(sub)
        sa_sub = SpacegroupAnalyzer(struct_sub)
        struct_sub = sa_sub.get_conventional_standard_structure()
        poscars_sub.append(Poscar(struct_sub))
    # 2d structures
    for td in mat2ds:
        poscars_2d.append(Poscar.from_file(td))
    # setup calibrate and run'em
    turn_knobs_sub = OrderedDict(
        [
            ('POSCAR', poscars_sub)
        ])
    turn_knobs_2d = OrderedDict(
        [
            ('POSCAR', poscars_2d)
        ])
    # normal binary
    qadapter_sub, job_cmd_sub = get_run_cmmnd(nnodes=nnodes, nprocs=nprocs,
                                            walltime=walltime,
                                            job_bin=bin_sub, mem=mem)