@@ -2493,19 +2493,19 @@ def to(self, filename: str = "", fmt: str = "", **kwargs) -> str | None:
2493
2493
from pymatgen .io .cssr import Cssr
2494
2494
2495
2495
writer = Cssr (self ) # type: ignore
2496
- elif fmt == "json" or fnmatch (filename .lower (), "*.json" ):
2497
- s = json .dumps (self .as_dict ())
2496
+ elif fmt == "json" or fnmatch (filename .lower (), "*.json* " ):
2497
+ dct = json .dumps (self .as_dict ())
2498
2498
if filename :
2499
- with zopen (filename , "wt" ) as f :
2500
- f .write (s )
2501
- return s
2499
+ with zopen (filename , "wt" ) as file :
2500
+ file .write (dct )
2501
+ return dct
2502
2502
elif fmt == "xsf" or fnmatch (filename .lower (), "*.xsf*" ):
2503
2503
from pymatgen .io .xcrysden import XSF
2504
2504
2505
2505
s = XSF (self ).to_string ()
2506
2506
if filename :
2507
- with zopen (filename , "wt" , encoding = "utf8" ) as f :
2508
- f .write (s )
2507
+ with zopen (filename , "wt" , encoding = "utf8" ) as file :
2508
+ file .write (s )
2509
2509
return s
2510
2510
elif (
2511
2511
fmt == "mcsqs"
@@ -2517,8 +2517,8 @@ def to(self, filename: str = "", fmt: str = "", **kwargs) -> str | None:
2517
2517
2518
2518
s = Mcsqs (self ).to_string ()
2519
2519
if filename :
2520
- with zopen (filename , "wt" , encoding = "ascii" ) as f :
2521
- f .write (s )
2520
+ with zopen (filename , "wt" , encoding = "ascii" ) as file :
2521
+ file .write (s )
2522
2522
return s
2523
2523
elif fmt == "prismatic" or fnmatch (filename , "*prismatic*" ):
2524
2524
from pymatgen .io .prismatic import Prismatic
@@ -2528,8 +2528,8 @@ def to(self, filename: str = "", fmt: str = "", **kwargs) -> str | None:
2528
2528
elif fmt == "yaml" or fnmatch (filename , "*.yaml*" ) or fnmatch (filename , "*.yml*" ):
2529
2529
yaml = YAML ()
2530
2530
if filename :
2531
- with zopen (filename , "wt" ) as f :
2532
- yaml .dump (self .as_dict (), f )
2531
+ with zopen (filename , "wt" ) as file :
2532
+ yaml .dump (self .as_dict (), file )
2533
2533
return None
2534
2534
sio = StringIO ()
2535
2535
yaml .dump (self .as_dict (), sio )
@@ -2543,8 +2543,8 @@ def to(self, filename: str = "", fmt: str = "", **kwargs) -> str | None:
2543
2543
2544
2544
s = ResIO .structure_to_str (self )
2545
2545
if filename :
2546
- with zopen (filename , "wt" , encoding = "utf8" ) as f :
2547
- f .write (s )
2546
+ with zopen (filename , "wt" , encoding = "utf8" ) as file :
2547
+ file .write (s )
2548
2548
return None
2549
2549
return s
2550
2550
else :
0 commit comments