@@ -591,95 +591,109 @@ def _compute_lower(self, output_file, all_tasks, all_res):
591591 cwd = Path .cwd ()
592592 work_path = Path (output_file ).parent .absolute ()
593593 output_file = os .path .abspath (output_file )
594+ resolved_tasks = []
595+ for task in all_tasks :
596+ task_path = Path (task )
597+ if task_path .is_absolute ():
598+ resolved_tasks .append (str (task_path ))
599+ elif (cwd / task_path ).exists ():
600+ resolved_tasks .append (str ((cwd / task_path ).absolute ()))
601+ elif task_path .parent == Path ("." ):
602+ resolved_tasks .append (str ((work_path / task_path ).absolute ()))
603+ else :
604+ resolved_tasks .append (str ((cwd / task_path ).absolute ()))
605+ all_tasks = resolved_tasks
594606 res_data = {}
595607 ptr_data = os .path .dirname (output_file ) + "\n "
596608
597609 band_path = loadfn (os .path .join (work_path , "band_path.json" ))
598610
599- if not self .reprod :
600- os .chdir (work_path )
601- if self .inter_param ["type" ] == 'abacus' :
602- self .check_same_copy ("task.000000/band.conf" , "band.conf" )
603- self .check_same_copy ("task.000000/STRU.ori" , "STRU" )
604- self .check_same_copy ("task.000000/phonopy_disp.yaml" , "phonopy_disp.yaml" )
605- subprocess .check_call (
606- self .phonopy_setup_command ("-f task.0*/OUT.ABACUS/running_scf.log" ),
607- shell = True ,
608- )
609- if not os .path .exists ("FORCE_SETS" ):
610- raise FileNotFoundError ("FORCE_SETS was not created" )
611- print ('FORCE_SETS is created' )
612- subprocess .check_call (self .phonopy_command ("band.conf" ), shell = True )
613- self .write_band_dat ()
614-
615- elif self .inter_param ["type" ] == 'vasp' :
616- self .check_same_copy ("task.000000/band.conf" , "band.conf" )
617- self .check_same_copy ("task.000000/POSCAR-unitcell" , "POSCAR-unitcell" )
618-
619- if self .approach == "linear" :
620- os .chdir (all_tasks [0 ])
621- assert os .path .isfile ('vasprun.xml' ), "vasprun.xml not found"
622- subprocess .check_call (self .phonopy_setup_command ("--fc vasprun.xml" ), shell = True )
623- assert os .path .isfile ('FORCE_CONSTANTS' ), "FORCE_CONSTANTS not created"
624- subprocess .check_call (self .phonopy_command ('--dim="%s %s %s" -c POSCAR-unitcell band.conf' % (
625- self .supercell_size [0 ],
626- self .supercell_size [1 ],
627- self .supercell_size [2 ])), shell = True )
628- self .write_band_dat ()
629- print ('band.dat is created' )
630- shutil .copyfile ("band.dat" , work_path / "band.dat" )
631-
632- elif self .approach == "displacement" :
611+ try :
612+ if not self .reprod :
613+ os .chdir (work_path )
614+ if self .inter_param ["type" ] == 'abacus' :
633615 self .check_same_copy ("task.000000/band.conf" , "band.conf" )
616+ self .check_same_copy ("task.000000/STRU.ori" , "STRU" )
634617 self .check_same_copy ("task.000000/phonopy_disp.yaml" , "phonopy_disp.yaml" )
635- subprocess .check_call (self .phonopy_setup_command ("-f task.0*/vasprun.xml" ), shell = True )
618+ subprocess .check_call (
619+ self .phonopy_setup_command ("-f task.0*/OUT.ABACUS/running_scf.log" ),
620+ shell = True ,
621+ )
636622 if not os .path .exists ("FORCE_SETS" ):
637623 raise FileNotFoundError ("FORCE_SETS was not created" )
638624 print ('FORCE_SETS is created' )
639- subprocess .check_call (self .phonopy_command ('--dim="%s %s %s" -c POSCAR-unitcell band.conf' % (
640- self .supercell_size [0 ],
641- self .supercell_size [1 ],
642- self .supercell_size [2 ])), shell = True )
625+ subprocess .check_call (self .phonopy_command ("band.conf" ), shell = True )
643626 self .write_band_dat ()
644627
645- elif self .inter_param ["type" ] in LAMMPS_INTER_TYPE :
646- os .chdir (all_tasks [0 ])
647- assert os .path .isfile ('FORCE_CONSTANTS' ), "FORCE_CONSTANTS not created"
648- subprocess .check_call (self .phonopy_command ('--dim="%s %s %s" -c POSCAR band.conf' % (
649- self .supercell_size [0 ], self .supercell_size [1 ], self .supercell_size [2 ])
650- ), shell = True )
651- self .write_band_dat ()
652- shutil .copyfile ("band.dat" , work_path / "band.dat" )
653-
654- else :
655- if "init_data_path" not in self .parameter :
656- raise RuntimeError ("please provide the initial data path to reproduce" )
657- init_data_path = os .path .abspath (self .parameter ["init_data_path" ])
658- res_data , ptr_data = post_repro (
659- init_data_path ,
660- self .parameter ["init_from_suffix" ],
661- all_tasks ,
662- ptr_data ,
663- self .parameter .get ("reprod_last_frame" , True ),
664- )
665-
666- os .chdir (work_path )
667- if not os .path .isfile ("band.dat" ):
668- raise FileNotFoundError ("band.dat was not created" )
669- with open ('band.dat' , 'r' ) as f :
670- ptr_data = f .read ()
628+ elif self .inter_param ["type" ] == 'vasp' :
629+ self .check_same_copy ("task.000000/band.conf" , "band.conf" )
630+ self .check_same_copy ("task.000000/POSCAR-unitcell" , "POSCAR-unitcell" )
631+
632+ if self .approach == "linear" :
633+ os .chdir (all_tasks [0 ])
634+ assert os .path .isfile ('vasprun.xml' ), "vasprun.xml not found"
635+ subprocess .check_call (self .phonopy_setup_command ("--fc vasprun.xml" ), shell = True )
636+ assert os .path .isfile ('FORCE_CONSTANTS' ), "FORCE_CONSTANTS not created"
637+ subprocess .check_call (self .phonopy_command ('--dim="%s %s %s" -c POSCAR-unitcell band.conf' % (
638+ self .supercell_size [0 ],
639+ self .supercell_size [1 ],
640+ self .supercell_size [2 ])), shell = True )
641+ self .write_band_dat ()
642+ print ('band.dat is created' )
643+ shutil .copyfile ("band.dat" , work_path / "band.dat" )
644+
645+ elif self .approach == "displacement" :
646+ self .check_same_copy ("task.000000/band.conf" , "band.conf" )
647+ self .check_same_copy ("task.000000/phonopy_disp.yaml" , "phonopy_disp.yaml" )
648+ subprocess .check_call (self .phonopy_setup_command ("-f task.0*/vasprun.xml" ), shell = True )
649+ if not os .path .exists ("FORCE_SETS" ):
650+ raise FileNotFoundError ("FORCE_SETS was not created" )
651+ print ('FORCE_SETS is created' )
652+ subprocess .check_call (self .phonopy_command ('--dim="%s %s %s" -c POSCAR-unitcell band.conf' % (
653+ self .supercell_size [0 ],
654+ self .supercell_size [1 ],
655+ self .supercell_size [2 ])), shell = True )
656+ self .write_band_dat ()
671657
672- if len ( ptr_data . split ( ' \n ' )) < 2 :
673- raise ValueError ( "band.dat is empty or malformed" )
674- result_points = ptr_data . split ( ' \n ' )[ 1 ][ 4 :]. split ()
675- result_lines = ptr_data . split ( ' \n ' )[ 2 :]
676- unpacked_lines = self .unpack_band ( ' \n ' . join ( result_lines ) )
677- res_data [ 'segment' ] = result_points
678- res_data [ 'band_path' ] = band_path
679- res_data [ 'band' ] = unpacked_lines
658+ elif self . inter_param [ "type" ] in LAMMPS_INTER_TYPE :
659+ os . chdir ( all_tasks [ 0 ] )
660+ assert os . path . isfile ( 'FORCE_CONSTANTS' ), "FORCE_CONSTANTS not created"
661+ subprocess . check_call ( self . phonopy_command ( '--dim="%s %s %s" -c POSCAR band.conf' % (
662+ self .supercell_size [ 0 ], self . supercell_size [ 1 ], self . supercell_size [ 2 ] )
663+ ), shell = True )
664+ self . write_band_dat ()
665+ shutil . copyfile ( "band.dat" , work_path / "band.dat" )
680666
681- with open (output_file , "w" ) as fp :
682- json .dump (res_data , fp , indent = 4 )
667+ else :
668+ if "init_data_path" not in self .parameter :
669+ raise RuntimeError ("please provide the initial data path to reproduce" )
670+ init_data_path = os .path .abspath (self .parameter ["init_data_path" ])
671+ res_data , ptr_data = post_repro (
672+ init_data_path ,
673+ self .parameter ["init_from_suffix" ],
674+ all_tasks ,
675+ ptr_data ,
676+ self .parameter .get ("reprod_last_frame" , True ),
677+ )
683678
684- os .chdir (cwd )
685- return res_data , ptr_data
679+ os .chdir (work_path )
680+ if not os .path .isfile ("band.dat" ):
681+ raise FileNotFoundError ("band.dat was not created" )
682+ with open ('band.dat' , 'r' ) as f :
683+ ptr_data = f .read ()
684+
685+ if len (ptr_data .split ('\n ' )) < 2 :
686+ raise ValueError ("band.dat is empty or malformed" )
687+ result_points = ptr_data .split ('\n ' )[1 ][4 :].split ()
688+ result_lines = ptr_data .split ('\n ' )[2 :]
689+ unpacked_lines = self .unpack_band ('\n ' .join (result_lines ))
690+ res_data ['segment' ] = result_points
691+ res_data ['band_path' ] = band_path
692+ res_data ['band' ] = unpacked_lines
693+
694+ with open (output_file , "w" ) as fp :
695+ json .dump (res_data , fp , indent = 4 )
696+
697+ return res_data , ptr_data
698+ finally :
699+ os .chdir (cwd )
0 commit comments