@@ -1296,7 +1296,11 @@ def style(self, style: str | KpointsSupportedModes) -> None:
1296
1296
self ._style = style
1297
1297
1298
1298
@classmethod
1299
- def automatic (cls , subdivisions : int ) -> Self :
1299
+ def automatic (
1300
+ cls ,
1301
+ subdivisions : int ,
1302
+ comment : str = "Fully automatic kpoint scheme" ,
1303
+ ) -> Self :
1300
1304
"""
1301
1305
Constructor for a fully automatic Kpoint grid, with
1302
1306
Gamma-centered grids and the number of subdivisions
@@ -1306,14 +1310,15 @@ def automatic(cls, subdivisions: int) -> Self:
1306
1310
Args:
1307
1311
subdivisions (int): Number of subdivisions along
1308
1312
each reciprocal lattice vector.
1313
+ comment (str): Comment in Kpoints.
1309
1314
1310
1315
Returns:
1311
1316
Kpoints
1312
1317
"""
1313
1318
warnings .warn ("Please use INCAR KSPACING tag." , DeprecationWarning , stacklevel = 2 )
1314
1319
1315
1320
return cls (
1316
- "Fully automatic kpoint scheme" ,
1321
+ comment ,
1317
1322
0 ,
1318
1323
style = cls .supported_modes .Automatic ,
1319
1324
kpts = [
@@ -1322,49 +1327,67 @@ def automatic(cls, subdivisions: int) -> Self:
1322
1327
)
1323
1328
1324
1329
@classmethod
1325
- def gamma_automatic (cls , kpts : Tuple3Ints = (1 , 1 , 1 ), shift : Vector3D = (0 , 0 , 0 )) -> Self :
1330
+ def gamma_automatic (
1331
+ cls ,
1332
+ kpts : Tuple3Ints = (1 , 1 , 1 ),
1333
+ shift : Vector3D = (0 , 0 , 0 ),
1334
+ comment : str = "Automatic kpoint scheme" ,
1335
+ ) -> Self :
1326
1336
"""
1327
1337
Construct an automatic Gamma-centered Kpoint grid.
1328
1338
1329
1339
Args:
1330
1340
kpts: Subdivisions N_1, N_2 and N_3 along reciprocal lattice
1331
1341
vectors. Defaults to (1, 1, 1)
1332
1342
shift: Shift to be applied to the kpoints. Defaults to (0, 0, 0).
1343
+ comment (str): Comment in Kpoints.
1333
1344
1334
1345
Returns:
1335
1346
Kpoints
1336
1347
"""
1337
1348
return cls (
1338
- "Automatic kpoint scheme" ,
1349
+ comment ,
1339
1350
0 ,
1340
1351
cls .supported_modes .Gamma ,
1341
1352
kpts = [kpts ],
1342
1353
kpts_shift = shift ,
1343
1354
)
1344
1355
1345
1356
@classmethod
1346
- def monkhorst_automatic (cls , kpts : Tuple3Ints = (2 , 2 , 2 ), shift : Vector3D = (0 , 0 , 0 )) -> Self :
1357
+ def monkhorst_automatic (
1358
+ cls ,
1359
+ kpts : Tuple3Ints = (2 , 2 , 2 ),
1360
+ shift : Vector3D = (0 , 0 , 0 ),
1361
+ comment : str = "Automatic kpoint scheme" ,
1362
+ ) -> Self :
1347
1363
"""
1348
1364
Construct an automatic Monkhorst-Pack Kpoint grid.
1349
1365
1350
1366
Args:
1351
1367
kpts: Subdivisions N_1, N_2, N_3 along reciprocal lattice
1352
1368
vectors. Defaults to (2, 2, 2)
1353
1369
shift: Shift to be applied to the kpoints. Defaults to (0, 0, 0).
1370
+ comment (str): Comment in Kpoints.
1354
1371
1355
1372
Returns:
1356
1373
Kpoints
1357
1374
"""
1358
1375
return cls (
1359
- "Automatic kpoint scheme" ,
1376
+ comment ,
1360
1377
0 ,
1361
1378
cls .supported_modes .Monkhorst ,
1362
1379
kpts = [kpts ],
1363
1380
kpts_shift = shift ,
1364
1381
)
1365
1382
1366
1383
@classmethod
1367
- def automatic_density (cls , structure : Structure , kppa : float , force_gamma : bool = False ) -> Self :
1384
+ def automatic_density (
1385
+ cls ,
1386
+ structure : Structure ,
1387
+ kppa : float ,
1388
+ force_gamma : bool = False ,
1389
+ comment : str | None = None ,
1390
+ ) -> Self :
1368
1391
"""Get an automatic Kpoints object based on a structure and a kpoint
1369
1392
density. Uses Gamma centered meshes for hexagonal cells and face-centered cells,
1370
1393
Monkhorst-Pack grids otherwise.
@@ -1374,15 +1397,18 @@ def automatic_density(cls, structure: Structure, kppa: float, force_gamma: bool
1374
1397
reciprocal lattice vector proportional to its length.
1375
1398
1376
1399
Args:
1377
- structure (Structure): Input structure
1378
- kppa (float): Grid density
1400
+ structure (Structure): Input structure.
1401
+ kppa (float): Grid density.
1379
1402
force_gamma (bool): Force a gamma centered mesh (default is to
1380
- use gamma only for hexagonal cells or odd meshes)
1403
+ use gamma only for hexagonal cells or odd meshes).
1404
+ comment (str): Comment in Kpoints.
1381
1405
1382
1406
Returns:
1383
1407
Kpoints
1384
1408
"""
1385
- comment = f"pymatgen with grid density = { kppa :.0f} / number of atoms"
1409
+ if comment is None :
1410
+ comment = f"pymatgen with grid density = { kppa :.0f} / number of atoms"
1411
+
1386
1412
if math .fabs ((math .floor (kppa ** (1 / 3 ) + 0.5 )) ** 3 - kppa ) < 1 :
1387
1413
kppa += kppa * 0.01
1388
1414
lattice = structure .lattice
@@ -1409,7 +1435,12 @@ def automatic_density(cls, structure: Structure, kppa: float, force_gamma: bool
1409
1435
)
1410
1436
1411
1437
@classmethod
1412
- def automatic_gamma_density (cls , structure : Structure , kppa : float ) -> Self :
1438
+ def automatic_gamma_density (
1439
+ cls ,
1440
+ structure : Structure ,
1441
+ kppa : float ,
1442
+ comment : str | None = None ,
1443
+ ) -> Self :
1413
1444
"""Get an automatic Kpoints object based on a structure and a kpoint
1414
1445
density. Uses Gamma centered meshes always. For GW.
1415
1446
@@ -1418,9 +1449,13 @@ def automatic_gamma_density(cls, structure: Structure, kppa: float) -> Self:
1418
1449
reciprocal lattice vector proportional to its length.
1419
1450
1420
1451
Args:
1421
- structure: Input structure
1422
- kppa: Grid density
1452
+ structure (Structure): Input structure
1453
+ kppa (float): Grid density
1454
+ comment (str): Comment in Kpoints.
1423
1455
"""
1456
+ if comment is None :
1457
+ comment = f"pymatgen with grid density = { kppa :.0f} / number of atoms"
1458
+
1424
1459
lattice = structure .lattice
1425
1460
a , b , c = lattice .abc
1426
1461
n_grid = kppa / len (structure )
@@ -1436,8 +1471,6 @@ def automatic_gamma_density(cls, structure: Structure, kppa: float) -> Self:
1436
1471
1437
1472
style = cls .supported_modes .Gamma
1438
1473
1439
- comment = f"pymatgen with grid density = { kppa :.0f} / number of atoms"
1440
-
1441
1474
n_kpts = 0
1442
1475
return cls (
1443
1476
comment ,
@@ -1448,31 +1481,39 @@ def automatic_gamma_density(cls, structure: Structure, kppa: float) -> Self:
1448
1481
)
1449
1482
1450
1483
@classmethod
1451
- def automatic_density_by_vol (cls , structure : Structure , kppvol : int , force_gamma : bool = False ) -> Self :
1484
+ def automatic_density_by_vol (
1485
+ cls ,
1486
+ structure : Structure ,
1487
+ kppvol : int ,
1488
+ force_gamma : bool = False ,
1489
+ comment : str | None = None ,
1490
+ ) -> Self :
1452
1491
"""Get an automatic Kpoints object based on a structure and a kpoint
1453
1492
density per inverse Angstrom^3 of reciprocal cell.
1454
1493
1455
1494
Algorithm:
1456
1495
Same as automatic_density()
1457
1496
1458
1497
Args:
1459
- structure (Structure): Input structure
1460
- kppvol (int): Grid density per Angstrom^(-3) of reciprocal cell
1461
- force_gamma (bool): Force a gamma centered mesh
1498
+ structure (Structure): Input structure.
1499
+ kppvol (int): Grid density per Angstrom^(-3) of reciprocal cell.
1500
+ force_gamma (bool): Force a gamma centered mesh.
1501
+ comment (str): Comment in Kpoints.
1462
1502
1463
1503
Returns:
1464
1504
Kpoints
1465
1505
"""
1466
1506
vol = structure .lattice .reciprocal_lattice .volume
1467
1507
kppa = kppvol * vol * len (structure )
1468
- return cls .automatic_density (structure , kppa , force_gamma = force_gamma )
1508
+ return cls .automatic_density (structure , kppa , force_gamma = force_gamma , comment = comment )
1469
1509
1470
1510
@classmethod
1471
1511
def automatic_density_by_lengths (
1472
1512
cls ,
1473
1513
structure : Structure ,
1474
1514
length_densities : Sequence [float ],
1475
1515
force_gamma : bool = False ,
1516
+ comment : str | None = None ,
1476
1517
) -> Self :
1477
1518
"""Get an automatic Kpoints object based on a structure and a k-point
1478
1519
density normalized by lattice constants.
@@ -1483,18 +1524,20 @@ def automatic_density_by_lengths(
1483
1524
have k-points of 50/a x 50/b x 1/c.
1484
1525
1485
1526
Args:
1486
- structure (Structure): Input structure
1487
- length_densities (list[float]): Defines the density of k-points in each
1527
+ structure (Structure): Input structure.
1528
+ length_densities (list[float]): Defines the density of k-points in each.
1488
1529
dimension, e.g. [50.0, 50.0, 1.0].
1489
- force_gamma (bool): Force a gamma centered mesh
1530
+ force_gamma (bool): Force a gamma centered mesh.
1531
+ comment (str): Comment in Kpoints.
1490
1532
1491
1533
Returns:
1492
1534
Kpoints
1493
1535
"""
1494
1536
if len (length_densities ) != 3 :
1495
1537
raise ValueError (f"The dimensions of length_densities must be 3, not { len (length_densities )} " )
1496
1538
1497
- comment : str = f"k-point density of { length_densities } /[a, b, c]"
1539
+ if comment is None :
1540
+ comment = f"k-point density of { length_densities } /[a, b, c]"
1498
1541
1499
1542
lattice = structure .lattice
1500
1543
@@ -1520,16 +1563,22 @@ def automatic_density_by_lengths(
1520
1563
)
1521
1564
1522
1565
@classmethod
1523
- def automatic_linemode (cls , divisions : int , ibz : HighSymmKpath ) -> Self :
1566
+ def automatic_linemode (
1567
+ cls ,
1568
+ divisions : int ,
1569
+ ibz : HighSymmKpath ,
1570
+ comment : str = "Line_mode KPOINTS file" ,
1571
+ ) -> Self :
1524
1572
"""
1525
1573
Convenient static constructor for a KPOINTS in mode line_mode.
1526
1574
gamma centered Monkhorst-Pack grids and the number of subdivisions
1527
1575
along each reciprocal lattice vector determined by the scheme in the
1528
1576
VASP manual.
1529
1577
1530
1578
Args:
1531
- divisions: Parameter determining the number of k-points along each high symmetry line.
1532
- ibz: HighSymmKpath object (pymatgen.symmetry.bandstructure)
1579
+ divisions (int): Parameter determining the number of k-points along each high symmetry line.
1580
+ ibz (HighSymmKpath): HighSymmKpath object (pymatgen.symmetry.bandstructure).
1581
+ comment (str): Comment in Kpoints.
1533
1582
1534
1583
Returns:
1535
1584
Kpoints object
@@ -1547,7 +1596,7 @@ def automatic_linemode(cls, divisions: int, ibz: HighSymmKpath) -> Self:
1547
1596
labels .append (path [- 1 ])
1548
1597
1549
1598
return cls (
1550
- "Line_mode KPOINTS file" ,
1599
+ comment ,
1551
1600
style = cls .supported_modes .Line_mode ,
1552
1601
coord_type = "Reciprocal" ,
1553
1602
kpts = kpoints ,
@@ -1591,7 +1640,7 @@ def from_str(cls, string: str) -> Self:
1591
1640
1592
1641
# Fully automatic KPOINTS
1593
1642
if style == "a" :
1594
- return cls .automatic (int (lines [3 ].split ()[0 ].strip ()))
1643
+ return cls .automatic (int (lines [3 ].split ()[0 ].strip ()), comment = comment )
1595
1644
1596
1645
coord_pattern = re .compile (r"^\s*([\d+.\-Ee]+)\s+([\d+.\-Ee]+)\s+([\d+.\-Ee]+)" )
1597
1646
@@ -1614,7 +1663,11 @@ def from_str(cls, string: str) -> Self:
1614
1663
1615
1664
kpts_shift = cast (Vector3D , tuple (_kpts_shift ))
1616
1665
1617
- return cls .gamma_automatic (kpt , kpts_shift ) if style == "g" else cls .monkhorst_automatic (kpt , kpts_shift )
1666
+ return (
1667
+ cls .gamma_automatic (kpt , kpts_shift , comment = comment )
1668
+ if style == "g"
1669
+ else cls .monkhorst_automatic (kpt , kpts_shift , comment = comment )
1670
+ )
1618
1671
1619
1672
# Automatic kpoints with basis
1620
1673
if num_kpts <= 0 :
@@ -1709,7 +1762,7 @@ def write_file(self, filename: PathLike) -> None:
1709
1762
with zopen (filename , mode = "wt" ) as file :
1710
1763
file .write (str (self ))
1711
1764
1712
- def as_dict (self ) -> dict :
1765
+ def as_dict (self ) -> dict [ str , Any ] :
1713
1766
"""MSONable dict."""
1714
1767
dct = {
1715
1768
"@module" : type (self ).__module__ ,
@@ -1734,7 +1787,7 @@ def as_dict(self) -> dict:
1734
1787
return dct
1735
1788
1736
1789
@classmethod
1737
- def from_dict (cls , dct : dict ) -> Self :
1790
+ def from_dict (cls , dct : dict [ str , Any ] ) -> Self :
1738
1791
"""
1739
1792
Args:
1740
1793
dct (dict): Dict representation.
@@ -1803,9 +1856,9 @@ class OrbitalDescription(NamedTuple):
1803
1856
1804
1857
1805
1858
# Hashes computed from the full POTCAR file contents by pymatgen (not 1st-party VASP hashes)
1806
- PYMATGEN_POTCAR_HASHES = loadfn (f"{ MODULE_DIR } /vasp_potcar_pymatgen_hashes.json" )
1859
+ PYMATGEN_POTCAR_HASHES : dict = loadfn (f"{ MODULE_DIR } /vasp_potcar_pymatgen_hashes.json" )
1807
1860
# Written to some newer POTCARs by VASP
1808
- VASP_POTCAR_HASHES = loadfn (f"{ MODULE_DIR } /vasp_potcar_file_hashes.json" )
1861
+ VASP_POTCAR_HASHES : dict = loadfn (f"{ MODULE_DIR } /vasp_potcar_file_hashes.json" )
1809
1862
POTCAR_STATS_PATH : str = os .path .join (MODULE_DIR , "potcar-summary-stats.json.bz2" )
1810
1863
1811
1864
0 commit comments