Skip to content

pwin

Classes for reading/manipulating PWscf xml files.

ControlNamelist(*args, **kwargs)

Bases: InputNamelist

&CONTROL namelist

Source code in pymatgen/io/espresso/inputs/base.py
227
228
def __init__(self, *args, **kwargs):
    super().__init__(*args, **kwargs)

SystemNamelist(*args, **kwargs)

Bases: InputNamelist

&SYSTEM namelist

Source code in pymatgen/io/espresso/inputs/base.py
227
228
def __init__(self, *args, **kwargs):
    super().__init__(*args, **kwargs)

ElectronsNamelist(*args, **kwargs)

Bases: InputNamelist

&ELECTRONS namelist

Source code in pymatgen/io/espresso/inputs/base.py
227
228
def __init__(self, *args, **kwargs):
    super().__init__(*args, **kwargs)

IonsNamelist(*args, **kwargs)

Bases: InputNamelist

&IONS namelist

Source code in pymatgen/io/espresso/inputs/base.py
227
228
def __init__(self, *args, **kwargs):
    super().__init__(*args, **kwargs)

CellNamelist(*args, **kwargs)

Bases: InputNamelist

&CELL namelist

Source code in pymatgen/io/espresso/inputs/base.py
227
228
def __init__(self, *args, **kwargs):
    super().__init__(*args, **kwargs)

FcpNamelist(*args, **kwargs)

Bases: InputNamelist

&FCP namelist

Source code in pymatgen/io/espresso/inputs/base.py
227
228
def __init__(self, *args, **kwargs):
    super().__init__(*args, **kwargs)

RismNamelist(*args, **kwargs)

Bases: InputNamelist

&RISM namelist

Source code in pymatgen/io/espresso/inputs/base.py
227
228
def __init__(self, *args, **kwargs):
    super().__init__(*args, **kwargs)

AtomicSpeciesCard(option, symbols, masses, files)

Bases: InputCard

ATOMIC_SPECIES card

symbols: List of atomic symbols
masses: List of atomic masses
files: List of pseudopotential file names
Source code in pymatgen/io/espresso/inputs/pwin.py
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
def __init__(
    self,
    option: str | CardOptions,
    symbols: list[str],
    masses: list[float],
    files: list[str],
):
    """
    Args:
        option: The option for the card
        symbols: List of atomic symbols
        masses: List of atomic masses
        files: List of pseudopotential file names
    """
    # TODO: cards that have no option shouldn't have an option parameter
    # in the constructor
    self.symbols = symbols
    self.masses = masses
    self.files = files
    super().__init__(option, None)

from_string(s) classmethod

Parse a string containing an ATOMIC_SPECIES card

Source code in pymatgen/io/espresso/inputs/pwin.py
111
112
113
114
115
116
117
118
@classmethod
def from_string(cls, s: str):
    """Parse a string containing an ATOMIC_SPECIES card"""
    option, body = cls.split_card_string(s)
    symbols = [item[0] for item in body]
    masses = [item[1] for item in body]
    files = [item[2] for item in body]
    return cls(option, symbols, masses, files)

AtomicPositionsCard(option, symbols, positions, force_multipliers)

Bases: InputCard

ATOMIC_POSITIONS card

symbols: List of atomic symbols
positions: List of atomic positions
force_multipliers: List of force multipliers (0 or 1 for each atom's x, y, z coordinates. 0 means fixed, 1 means can move. See pw.x documentation for more details.)
Source code in pymatgen/io/espresso/inputs/pwin.py
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def __init__(
    self,
    option: str | "CardOptions",
    symbols: list[str],
    positions: np.ndarray,
    force_multipliers: np.ndarray,
):
    """
    Args:
        option: The option for the card
        symbols: List of atomic symbols
        positions: List of atomic positions
        force_multipliers: List of force multipliers (0 or 1 for each atom's x, y, z coordinates. 0 means fixed, 1 means can move. See pw.x documentation for more details.)
    """
    self.option = option
    self.symbols = symbols
    assert len(symbols) == len(positions)
    self.positions = positions
    if force_multipliers is None:
        force_multipliers = [[1, 1, 1] for _ in range(len(symbols))]
    else:
        assert len(force_multipliers) == len(symbols)
    self.force_multipliers = force_multipliers
    super().__init__(option, None)

from_string(s) classmethod

Parse a string containing an ATOMIC_SPECIES card

Source code in pymatgen/io/espresso/inputs/pwin.py
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
@classmethod
def from_string(cls, s: str):
    """Parse a string containing an ATOMIC_SPECIES card"""
    option, body = cls.split_card_string(s)

    # Check if all lines of body have same length
    if any(len(line) != len(body[0]) for line in body) or len(body[0]) not in [
        4,
        7,
    ]:
        print([len(line) for line in body])
        raise PWinParserError(
            "All lines in ATOMIC_POSITIONS card must have the same number of columns, either 4 or 7"
        )
    symbols = [line[0] for line in body]
    positions = [np.array(line[1:4]) for line in body]
    force_multipliers = [line[4:] for line in body] if len(body[0]) == 7 else None
    if force_multipliers is not None and any(
        any(f not in [0, 1] for f in fm) for fm in force_multipliers
    ):
        raise PWinParserError(
            "All force multipliers in ATOMIC_POSITIONS card must be either 0 or 1"
        )

    return cls(option, symbols, positions, force_multipliers)

KPointsCard(option, grid, shift, k, weights, labels)

Bases: InputCard

K_POINTS card

Source code in pymatgen/io/espresso/inputs/pwin.py
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
def __init__(
    self,
    option: KPointsOptions | str,
    grid: list,
    shift: list,
    k: list[list[float]] | np.ndarray,
    weights: list[float] | np.ndarray,
    labels: list[str],
):
    # TODO make labels a dict with index as key, much easier to work with
    self.grid = grid
    self.shift = shift
    self.k = k
    self.weights = weights
    self.labels = labels
    super().__init__(option, None)

line_mode: bool property

Whether the k-points are in line mode

band_mode: bool property

Whether the k-points are in band mode

coords_are_cartesian: bool property

Whether the k-points are in cartesian coordinates

from_string(s) classmethod

Parse a string containing K_POINTS card

Source code in pymatgen/io/espresso/inputs/pwin.py
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
@classmethod
def from_string(cls, s: str) -> KPointsCard:
    """Parse a string containing K_POINTS card"""
    option, body = cls.split_card_string(s)
    grid, shift, k, weights, labels = [], [], [], [], []
    if option == "automatic":
        grid, shift = body[0][:3], [bool(s) for s in body[0][3:]]
    elif option != "gamma":
        for line in body[1:]:
            k.append(line[:3])
            weights.append(line[3])
            labels.append(
                " ".join(line[4:]).strip("!").lstrip() if len(line) > 4 else ""
            )

    return cls(option, grid, shift, k, weights, labels)

AdditionalKPointsCard(option, k, weights, labels)

Bases: InputCard

ADDITIONAL_K_POINTS card

Source code in pymatgen/io/espresso/inputs/pwin.py
311
312
313
314
315
316
317
318
319
320
321
322
def __init__(
    self,
    option: AdditionalKPointsOptions | str,
    k: list[list[float]] | np.ndarray,
    weights: list[float] | np.ndarray,
    labels: list[str],
):
    # TODO make labels a dict with index as key, much easier to work with
    self.k = k
    self.weights = weights
    self.labels = labels
    super().__init__(option, None)

from_string(s) classmethod

Parse a string containing an ATOMIC_SPECIES card

Source code in pymatgen/io/espresso/inputs/pwin.py
332
333
334
335
336
337
338
339
340
341
342
343
344
@classmethod
def from_string(cls, s: str) -> AdditionalKPointsCard:
    """Parse a string containing an ATOMIC_SPECIES card"""
    option, body = cls.split_card_string(s)
    k, weights, labels = [], [], []
    for line in body[1:]:
        k.append(line[:3])
        weights.append(line[3])
        labels.append(
            " ".join(line[4:]).strip("!").lstrip() if len(line) > 4 else ""
        )

    return cls(option, k, weights, labels)

CellParametersCard(option, a1, a2, a3)

Bases: InputCard

CELL_PARAMETERS card

Source code in pymatgen/io/espresso/inputs/pwin.py
361
362
363
364
365
366
367
368
369
def __init__(
    self,
    option: CellParametersOptions,
    a1: np.ndarray,
    a2: np.ndarray,
    a3: np.ndarray,
):
    self.a1, self.a2, self.a3 = a1, a2, a3
    super().__init__(option, None)

from_string(s) classmethod

Parse a string containing an ATOMIC_SPECIES card

Source code in pymatgen/io/espresso/inputs/pwin.py
389
390
391
392
393
394
@classmethod
def from_string(cls, s: str) -> CellParametersCard:
    """Parse a string containing an ATOMIC_SPECIES card"""
    option, body = cls.split_card_string(s)
    a1, a2, a3 = map(lambda x: np.array(x, dtype=float), body)
    return cls(option, a1, a2, a3)

ConstraintsCard(option, body)

Bases: InputCard

CONSTRAINTS card (not fully implemented)

body (list): The body of the card
Source code in pymatgen/io/espresso/inputs/base.py
261
262
263
264
265
266
267
268
269
270
def __init__(self, option: str | CardOptions, body: str):
    """
    Args:
        option (str): The option for the card (e.g., "RELAX")
        body (list): The body of the card
    """
    if isinstance(option, str):
        option = self.opts.from_string(option)
    self.option = option
    self._body = body

OccupationsCard(option, body)

Bases: InputCard

OCCUPATIONS card (not fully implemented)

body (list): The body of the card
Source code in pymatgen/io/espresso/inputs/base.py
261
262
263
264
265
266
267
268
269
270
def __init__(self, option: str | CardOptions, body: str):
    """
    Args:
        option (str): The option for the card (e.g., "RELAX")
        body (list): The body of the card
    """
    if isinstance(option, str):
        option = self.opts.from_string(option)
    self.option = option
    self._body = body

AtomicVelocitiesCard(option, body)

Bases: InputCard

ATOMIC_VELOCITIES card (not fully implemented)

body (list): The body of the card
Source code in pymatgen/io/espresso/inputs/base.py
261
262
263
264
265
266
267
268
269
270
def __init__(self, option: str | CardOptions, body: str):
    """
    Args:
        option (str): The option for the card (e.g., "RELAX")
        body (list): The body of the card
    """
    if isinstance(option, str):
        option = self.opts.from_string(option)
    self.option = option
    self._body = body

AtomicForcesCard(option, body)

Bases: InputCard

ATOMIC_FORCES card (not fully implemented)

body (list): The body of the card
Source code in pymatgen/io/espresso/inputs/base.py
261
262
263
264
265
266
267
268
269
270
def __init__(self, option: str | CardOptions, body: str):
    """
    Args:
        option (str): The option for the card (e.g., "RELAX")
        body (list): The body of the card
    """
    if isinstance(option, str):
        option = self.opts.from_string(option)
    self.option = option
    self._body = body

SolventsCard(option, body)

Bases: InputCard

SOLVENTS card (not fully implemented)

body (list): The body of the card
Source code in pymatgen/io/espresso/inputs/base.py
261
262
263
264
265
266
267
268
269
270
def __init__(self, option: str | CardOptions, body: str):
    """
    Args:
        option (str): The option for the card (e.g., "RELAX")
        body (list): The body of the card
    """
    if isinstance(option, str):
        option = self.opts.from_string(option)
    self.option = option
    self._body = body

HubbardCard(option, body)

Bases: InputCard

HUBBARD card (not fully implemented)

body (list): The body of the card
Source code in pymatgen/io/espresso/inputs/base.py
261
262
263
264
265
266
267
268
269
270
def __init__(self, option: str | CardOptions, body: str):
    """
    Args:
        option (str): The option for the card (e.g., "RELAX")
        body (list): The body of the card
    """
    if isinstance(option, str):
        option = self.opts.from_string(option)
    self.option = option
    self._body = body

PWin(namelists, cards)

Bases: BaseInputFile

Class for PWscf input files. Unlikely to be constructed directly, use the from_file method instead.

The namelist attributes pretty much work like dictionaries, while the card attributes are all based on the InputCard class and its subclasses.

ATTRIBUTE DESCRIPTION
structure

Structure object

TYPE: Structure

lattice

Lattice object

TYPE: Lattice

alat

alat (either celldm(1) or A) in ANGSTROM

TYPE: float

site_symbols

List of site symbols in the input file

TYPE: list

celldm

List of celldm parameters (6 elements, first is alat in ANGSTROM)

TYPE: list

atomic_species

ATOMIC_SPECIES card

TYPE: AtomicSpeciesCard

atomic_positions

ATOMIC_POSITIONS card

TYPE: AtomicPositionsCard

k_points

K_POINTS card

TYPE: KPointsCard

additional_k_points

ADDITIONAL_K_POINTS card

TYPE: AdditionalKPointsCard

cell_parameters

CELL_PARAMETERS card

TYPE: CellParametersCard

constraints

CONSTRAINTS card

TYPE: ConstraintsCard

occupations

OCCUPATIONS card

TYPE: OccupationsCard

atomic_velocities

ATOMIC_VELOCITIES card

TYPE: AtomicVelocitiesCard

atomic_forces

ATOMIC_FORCES card

TYPE: AtomicForcesCard

solvents

SOLVENTS card

TYPE: SolventsCard

hubbard

HUBBARD card

TYPE: HubbardCard

control

&CONTROL namelist

TYPE: ControlNamelist

system

&SYSTEM namelist

TYPE: SystemNamelist

electrons

&ELECTRONS namelist

TYPE: ElectronsNamelist

ions

&IONS namelist

TYPE: IonsNamelist

cell

&CELL namelist

TYPE: CellNamelist

fcp

&FCP namelist

TYPE: FcpNamelist

rism

&RISM nam

TYPE: RismNamelist

Source code in pymatgen/io/espresso/inputs/base.py
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
def __init__(self, namelists: list[dict[str, Any]], cards: list["InputCard"]):
    namelist_names = [nml.value.name for nml in self.namelist_classes]
    self.namelists = OrderedDict(
        {name: namelists.get(name, None) for name in namelist_names}
    )
    card_names = [c.value.name for c in self.card_classes]
    self.cards = OrderedDict({name: cards.get(name, None) for name in card_names})
    property_names = namelist_names + card_names
    for prop_name in property_names:
        setattr(
            self.__class__,
            prop_name,
            property(
                self._make_getter(prop_name),
                self._make_setter(prop_name),
                self._make_deleter(prop_name),
            ),
        )

site_symbols property

The list of site symbols in the input file (i.e., the atomic_species card)

structure: Structure property writable

RETURNS DESCRIPTION
Structure

Structure object

lattice: Lattice property writable

RETURNS DESCRIPTION
Lattice

Lattice object (in ANGSTROM no matter what's in the input file)

alat: float property

Returns alat (either celldm(1) or A) in ANGSTROM with proper error handling

celldm: list property

Gets celldm from the input file. If celldm is in the input file, returns it with the first element converted to angstrom and padded with zeros to length 6. If A is in the input instead, then it returns: celldm = [A, B/A, C/A, cosBC, cosAC, cosAB] (with A in angstrom) with missing values padded to zeros

RETURNS DESCRIPTION
celldm

list of celldm parameters, with shape (6,)

TYPE: list

PWinCards

Bases: SupportedInputs

Supported input cards for PWscf input files

PWinNamelists

Bases: SupportedInputs

Supported namelists for PWscf input files

PWinParserError

Bases: Exception

Exception class for PWin parsing.