@@ -2555,7 +2555,7 @@ def get_primitive_structure(
2555
2555
tolerance : float = 0.25 ,
2556
2556
use_site_props : bool = False ,
2557
2557
constrain_latt : list | dict | None = None ,
2558
- ) -> Self :
2558
+ ) -> Self | Structure :
2559
2559
"""Find a smaller unit cell than the input. Sometimes it doesn't
2560
2560
find the smallest possible one, so this method is recursively called
2561
2561
until it is unable to find a smaller cell.
@@ -3190,7 +3190,7 @@ def from_file( # type:ignore[override]
3190
3190
3191
3191
fname = os .path .basename (filename )
3192
3192
with zopen (filename , mode = "rt" , errors = "replace" , encoding = "utf-8" ) as file :
3193
- contents = file .read ()
3193
+ contents : str = file .read ()
3194
3194
if fnmatch (fname .lower (), "*.cif*" ) or fnmatch (fname .lower (), "*.mcif*" ):
3195
3195
return cls .from_str (
3196
3196
contents ,
@@ -4013,7 +4013,7 @@ def to(self, filename: str = "", fmt: str = "") -> str | None:
4013
4013
json_str = json .dumps (self .as_dict ())
4014
4014
if filename :
4015
4015
with zopen (filename , mode = "wt" , encoding = "utf-8" ) as file :
4016
- file .write (json_str )
4016
+ file .write (json_str . encode ( "utf-8" ) )
4017
4017
return json_str
4018
4018
elif fmt in {"yaml" , "yml" } or fnmatch (filename , "*.yaml*" ) or fnmatch (filename , "*.yml*" ):
4019
4019
yaml = YAML ()
@@ -4022,7 +4022,7 @@ def to(self, filename: str = "", fmt: str = "") -> str | None:
4022
4022
yaml_str = str_io .getvalue ()
4023
4023
if filename :
4024
4024
with zopen (filename , mode = "wt" , encoding = "utf-8" ) as file :
4025
- file .write (yaml_str )
4025
+ file .write (yaml_str . encode ( "utf-8" ) )
4026
4026
return yaml_str
4027
4027
else :
4028
4028
from pymatgen .io .babel import BabelMolAdaptor
@@ -4088,7 +4088,7 @@ def from_str( # type:ignore[override]
4088
4088
return cls .from_sites (mol , properties = mol .properties )
4089
4089
4090
4090
@classmethod
4091
- def from_file (cls , filename : PathLike ) -> Self | None : # type:ignore[override]
4091
+ def from_file (cls , filename : PathLike ) -> IMolecule | Molecule : # type:ignore[override]
4092
4092
"""Read a molecule from a file. Supported formats include xyz,
4093
4093
gaussian input (gjf|g03|g09|com|inp), Gaussian output (.out|and
4094
4094
pymatgen's JSON-serialized molecules. Using openbabel,
@@ -4104,7 +4104,7 @@ def from_file(cls, filename: PathLike) -> Self | None: # type:ignore[override]
4104
4104
filename = str (filename )
4105
4105
4106
4106
with zopen (filename , mode = "rt" , encoding = "utf-8" ) as file :
4107
- contents = file .read ()
4107
+ contents : str = file .read (). decode ( "utf-8" )
4108
4108
fname = filename .lower ()
4109
4109
if fnmatch (fname , "*.xyz*" ):
4110
4110
return cls .from_str (contents , fmt = "xyz" )
0 commit comments