Structure¶
- class py4vasp.data.Structure(raw_data)¶
Bases:
py4vasp.data._trajectory.DataTrajectory
The structure of the crystal for selected steps of the simulation.
You can use this class to process structural information from the Vasp calculation. Typically you want to do this to inspect the converged structure after an ionic relaxation or to visualize the changes of the structure along the simulation.
- Parameters
raw_structure (RawStructure) – Dataclass containing the raw data defining the structure.
Examples
If you access a method of this class, the result will depend on the steps that you selected with the [] operator. Without any selection the results from the final step will be used.
>>> calc.structure.read()
To select the results for all steps, you don’t specify the array boundaries.
>>> calc.structure[:].read()
You can also select specific steps or a subset of steps as follows
>>> calc.structure[5].read() >>> calc.structure[1:6].read()
Attributes Summary
Converting Å to nm used for mdtraj trajectories.
Methods Summary
Convert the positions from direct coordinates to cartesian ones.
from_POSCAR
(poscar)Generate a structure from string in POSCAR format.
from_ase
(structure)Generate a structure from the ase Atoms class.
from_dict
(dict_)Initialize refinement class from data dictionary
from_file
([file])Read the data dictionary from the given file.
Return the total number of atoms in the structure.
Return the number of structures in the trajectory.
plot
([supercell])Generate a 3d representation of the structure(s).
print
()Print a string representation of this class to standard output.
read
()Read the structual information into a dictionary.
Convert the structure(s) to a POSCAR format
to_ase
([supercell])Convert the structure to an ase Atoms object.
to_dict
()Read the structual information into a dictionary.
Convert the trajectory to mdtraj.Trajectory
to_viewer3d
([supercell])Generate a 3d representation of the structure(s).
volume
()Return the volume of the unit cell for the selected steps.
Attributes Documentation
- A_to_nm = 0.1¶
Converting Å to nm used for mdtraj trajectories.
Methods Documentation
- cartesian_positions()¶
Convert the positions from direct coordinates to cartesian ones.
- Returns
Position of all atoms in cartesian coordinates in Å.
- Return type
np.ndarray
Examples
If you access this method, the result will depend on the steps of the class that you selected with the [] operator. Without any selection the results from the final step will be used.
>>> calc.structure.cartesian_positions()
To select the results for all steps, you don’t specify the array boundaries.
>>> calc.structure[:].cartesian_positions()
You can also select specific steps or a subset of steps as follows
>>> calc.structure[5].cartesian_positions() >>> calc.structure[1:6].cartesian_positions()
- classmethod from_POSCAR(poscar)¶
Generate a structure from string in POSCAR format.
- classmethod from_ase(structure)¶
Generate a structure from the ase Atoms class.
- classmethod from_dict(dict_)¶
Initialize refinement class from data dictionary
- Parameters
data_dict (dict) – Data dictionary that contains one or more different raw data sources.
- classmethod from_file(file=None)¶
Read the data dictionary from the given file.
You want to use this method if you want to avoid using the Calculation wrapper, for example because you renamed the output of the VASP calculation.
- Parameters
file (str or Path or raw.File) – Filename from which the data is extracted. If not present the default filename is used. Alternatively, you can open the file yourself and pass the File object. In that case, you need to take care the file is properly closed again and be aware the generated instance of this class becomes unusable after the file is closed.
- Returns
The returned instance handles opening and closing the file for every function called on it, unless a File object in which case this is left to the user.
- Return type
DataBase
- number_atoms()¶
Return the total number of atoms in the structure.
- number_steps()¶
Return the number of structures in the trajectory.
- plot(supercell=None)¶
Generate a 3d representation of the structure(s).
- Parameters
supercell (int or np.ndarray) – If present the structure is replicated the specified number of times along each direction.
- Returns
Visualize the structure(s) as a 3d figure.
- Return type
Examples
If you access this method, the result will depend on the steps of the class that you selected with the [] operator. Without any selection the results from the final step will be used.
>>> calc.structure.plot()
To select the results for all steps, you don’t specify the array boundaries.
>>> calc.structure[:].plot()
You can also select specific steps or a subset of steps as follows
>>> calc.structure[5].plot() >>> calc.structure[1:6].plot()
- print()¶
Print a string representation of this class to standard output.
- read()¶
Read the structual information into a dictionary.
- Returns
Contains the unit cell of the crystal, as well as the position of all the atoms in units of the lattice vectors and the elements of the atoms for all selected steps.
- Return type
dict
Examples
If you access this method, the result will depend on the steps of the class that you selected with the [] operator. Without any selection the results from the final step will be used.
>>> calc.structure.read()
To select the results for all steps, you don’t specify the array boundaries.
>>> calc.structure[:].read()
You can also select specific steps or a subset of steps as follows
>>> calc.structure[5].read() >>> calc.structure[1:6].read()
- to_POSCAR()¶
Convert the structure(s) to a POSCAR format
- Returns
Returns the POSCAR of the current or all selected steps.
- Return type
str or list[str]
Examples
If you access this method, the result will depend on the steps of the class that you selected with the [] operator. Without any selection the results from the final step will be used.
>>> calc.structure.to_POSCAR()
To select the results for all steps, you don’t specify the array boundaries.
>>> calc.structure[:].to_POSCAR()
You can also select specific steps or a subset of steps as follows
>>> calc.structure[5].to_POSCAR() >>> calc.structure[1:6].to_POSCAR()
- to_ase(supercell=None)¶
Convert the structure to an ase Atoms object.
- Parameters
supercell (int or np.ndarray) – If present the structure is replicated the specified number of times along each direction.
- Returns
Structural information for ase package.
- Return type
ase.Atoms
Examples
If you access this method, the result will depend on the steps of the class that you selected with the [] operator. Without any selection the results from the final step will be used.
>>> calc.structure.to_ase()
To select the results for all steps, you don’t specify the array boundaries.
>>> calc.structure[:].to_ase()
You can also select specific steps or a subset of steps as follows
>>> calc.structure[5].to_ase() >>> calc.structure[1:6].to_ase()
- to_dict()¶
Read the structual information into a dictionary.
- Returns
Contains the unit cell of the crystal, as well as the position of all the atoms in units of the lattice vectors and the elements of the atoms for all selected steps.
- Return type
dict
Examples
If you access this method, the result will depend on the steps of the class that you selected with the [] operator. Without any selection the results from the final step will be used.
>>> calc.structure.read()
To select the results for all steps, you don’t specify the array boundaries.
>>> calc.structure[:].read()
You can also select specific steps or a subset of steps as follows
>>> calc.structure[5].read() >>> calc.structure[1:6].read()
- to_mdtraj()¶
Convert the trajectory to mdtraj.Trajectory
- Returns
The mdtraj package offers many functionalities to analyze a MD trajectory. By converting the Vasp data to their format, we facilitate using all functions of that package.
- Return type
mdtraj.Trajectory
Examples
If you access this method, the result will depend on the steps of the class that you selected with the [] operator. Without any selection the results from the final step will be used.
>>> calc.structure.to_mdtraj()
To select the results for all steps, you don’t specify the array boundaries.
>>> calc.structure[:].to_mdtraj()
You can also select specific steps or a subset of steps as follows
>>> calc.structure[5].to_mdtraj() >>> calc.structure[1:6].to_mdtraj()
- to_viewer3d(supercell=None)¶
Generate a 3d representation of the structure(s).
- Parameters
supercell (int or np.ndarray) – If present the structure is replicated the specified number of times along each direction.
- Returns
Visualize the structure(s) as a 3d figure.
- Return type
Examples
If you access this method, the result will depend on the steps of the class that you selected with the [] operator. Without any selection the results from the final step will be used.
>>> calc.structure.plot()
To select the results for all steps, you don’t specify the array boundaries.
>>> calc.structure[:].plot()
You can also select specific steps or a subset of steps as follows
>>> calc.structure[5].plot() >>> calc.structure[1:6].plot()
- volume()¶
Return the volume of the unit cell for the selected steps.
- Returns
The volume(s) of the selected step(s) in ų.
- Return type
float or np.ndarray
Examples
If you access this method, the result will depend on the steps of the class that you selected with the [] operator. Without any selection the results from the final step will be used.
>>> calc.structure.volume()
To select the results for all steps, you don’t specify the array boundaries.
>>> calc.structure[:].volume()
You can also select specific steps or a subset of steps as follows
>>> calc.structure[5].volume() >>> calc.structure[1:6].volume()