@@ -840,39 +840,45 @@ def _validate_euphonic_input_file(cls, filename_full_path: str) -> dict:
840
840
841
841
if (suffix := path .suffix ) == ".castep_bin" :
842
842
# Assume any .castep_bin file is valid choice
843
- pass
844
-
845
- elif suffix in (".yaml" , ".yml" ):
846
- # Check .yaml files have expected keys for Phonopy force constants
847
- with open (filename_full_path , "r" ) as yaml_file :
848
- phonon_data = yaml .load (yaml_file , Loader = SafeLoader )
849
-
850
- if {"phonopy" , "force_constants" }.issubset (phonon_data ):
851
- pass
852
-
853
- elif "phonopy" in phonon_data :
854
- # Phonopy file without force constants: they must be in another file
855
-
856
- # Check if following janus conventions:
857
- # /parent/seedname-phonopy.yml -> /parent/seedname-force_constants.hdf5
858
- janus_phonopy_re = "(?P<seedname>.+)-phonopy.yml"
859
- fc_filenames = ("FORCE_CONSTANTS" , "force_constants.hdf5" )
860
- if re_match := re .match (janus_phonopy_re , path .name ):
861
- fc_file = path .parent / f"{ re_match ['seedname' ]} -force_constants.hdf5"
862
- if not fc_file .is_file ():
863
- return dict (
864
- Invalid = True ,
865
- Comment = f"Could not find force constants in { filename_full_path } , or find data file { fc_file } " ,
866
- )
843
+ return dict (Invalid = False , Comment = "" )
867
844
868
- # Otherwise FC could be in a FORCE_CONSTANTS or force_constants.hdf5 file
869
- elif not any (map (lambda fc_filename : (path .parent / fc_filename ).is_file (), fc_filenames )):
870
- return dict (
871
- Invalid = True ,
872
- Comment = f"Could not find force constants in { filename_full_path } , or find data file { ' or ' .join (fc_filenames )} " ,
873
- )
845
+ if suffix not in (".yaml" , ".yml" ):
846
+ return dict (Invalid = True , Comment = "Invalid extension: FORCECONSTANTS requires .castep_bin, .yaml or .yml" )
847
+
848
+ # Check .yaml files have expected keys for Phonopy force constants
849
+ with open (filename_full_path , "r" ) as yaml_file :
850
+ phonon_data = yaml .load (yaml_file , Loader = SafeLoader )
851
+
852
+ if {"phonopy" , "force_constants" }.issubset (phonon_data ):
853
+ # Force constants are in the yaml file: good
854
+ return dict (Invalid = False , Comment = "" )
855
+
856
+ if "phonopy" not in phonon_data :
857
+ # Not a Phonopy file: can't use this
858
+ return dict (Invalid = True , Comment = f"No 'phonopy' section found in { filename_full_path } " )
859
+
860
+ # Phonopy file without force constants: they must be in another file
861
+
862
+ # Check if following janus conventions:
863
+ # /parent/seedname-phonopy.yml -> /parent/seedname-force_constants.hdf5
864
+ janus_phonopy_re = "(?P<seedname>.+)-phonopy.yml"
865
+ fc_filenames = ("FORCE_CONSTANTS" , "force_constants.hdf5" )
866
+ if re_match := re .match (janus_phonopy_re , path .name ):
867
+ fc_file = path .parent / f"{ re_match ['seedname' ]} -force_constants.hdf5"
868
+ if not fc_file .is_file ():
869
+ return dict (
870
+ Invalid = True ,
871
+ Comment = f"Could not find force constants in { filename_full_path } , or find data file { fc_file } " ,
872
+ )
873
+
874
+ # Otherwise FC could be in a FORCE_CONSTANTS or force_constants.hdf5 file
875
+ elif not any (map (lambda fc_filename : (path .parent / fc_filename ).is_file (), fc_filenames )):
876
+ return dict (
877
+ Invalid = True ,
878
+ Comment = f"Could not find force constants in { filename_full_path } , or find data file { ' or ' .join (fc_filenames )} " ,
879
+ )
874
880
875
- # Did not return already: No problems found
881
+ # Phonopy YAML with available force constants
876
882
return dict (Invalid = False , Comment = "" )
877
883
878
884
@classmethod
0 commit comments