@@ -354,7 +354,53 @@ def prepare_inputs_for_phase_diagram(inputyamlfile, calculation_base_name=None):
354354 else :
355355 raise ValueError ("Temperature range should be scalar of list of two values!" )
356356
357+
358+ #we do a first round - create lattices
359+ created_lattices = []
360+ created_comp_dicts = []
361+
362+ for count , comp in enumerate (comp_arr ):
363+ calc = copy .deepcopy (phase )
364+ n_atoms = np .sum (calc ['composition' ]['number_of_atoms' ])
365+
366+ if is_reference [count ]:
367+ outfile = fix_data_file (calc ['lattice' ], len (calc ['element' ]))
368+ input_chemical_composition = {element :number for element , number in zip (calc ['element' ],
369+ calc ['composition' ]['number_of_atoms' ])}
370+ created_lattices .append (outfile )
371+ created_comp_dicts .append (input_chemical_composition )
372+
373+ else :
374+ #write out the file
375+ output_chemical_composition = {}
376+ n_species_b = int (np .round (comp * n_atoms , decimals = 0 ))
377+ output_chemical_composition [reference_element ] = n_species_b
378+
379+ n_species_a = int (n_atoms - n_species_b )
380+ output_chemical_composition [other_element ] = n_species_a
381+
382+ if n_species_a == 0 :
383+ raise ValueError ("Please add pure phase as a new entry!" )
384+
385+ #create input comp dict - this works
386+ input_chemical_composition = {element :number for element , number in zip (calc ['element' ],
387+ calc ['composition' ]['number_of_atoms' ])}
388+
389+ folder_prefix = f'{ phase_name } -{ comp :.2f} '
390+ outfile = os .path .join (os .getcwd (), os .path .basename (calc ['lattice' ])+ folder_prefix + '.comp.mod' )
391+
392+ simplecalc = SimpleCalculation (calc ['lattice' ],
393+ calc ["element" ],
394+ input_chemical_composition ,
395+ output_chemical_composition )
396+ compsc = CompositionTransformation (simplecalc , keep_types = True )
397+ compsc .write_structure (outfile )
398+ created_lattices .append (outfile )
399+ created_comp_dicts .append (input_chemical_composition )
400+
401+ #now the actual run, where we prepare calculations
357402 all_calculations = []
403+ is_ref_count = np .argmax (is_reference )
358404
359405 for count , comp in enumerate (comp_arr ):
360406 #check if ref comp equals given comp
@@ -367,16 +413,13 @@ def prepare_inputs_for_phase_diagram(inputyamlfile, calculation_base_name=None):
367413 extra_keys = ['composition' , 'monte_carlo' ]
368414 for key in extra_keys :
369415 _ = calc .pop (key , None )
370-
371- #update file if needed
372- outfile = fix_data_file (calc ['lattice' ], len (calc ['element' ]))
373-
416+
374417 #add ref phase, needed
375418 calc ['reference_phase' ] = str (phase_reference_state )
376419 calc ['reference_composition' ] = comps ['reference' ]
377420 calc ['mode' ] = str ('fe' )
378421 calc ['folder_prefix' ] = f'{ phase_name } -{ comp :.2f} '
379- calc ['lattice' ] = str (outfile )
422+ calc ['lattice' ] = str (created_lattices [ count ] )
380423
381424 #now we need to run this for different temp
382425 for temp in temp_arr :
@@ -387,9 +430,6 @@ def prepare_inputs_for_phase_diagram(inputyamlfile, calculation_base_name=None):
387430 #off stoichiometric
388431 #copy the dict
389432 calc = copy .deepcopy (phase )
390-
391- #first thing first, we need to calculate the number of atoms
392- #we follow the convention that composition is always given with the second species
393433 n_atoms = np .sum (calc ['composition' ]['number_of_atoms' ])
394434
395435 #find number of atoms of second species
@@ -400,21 +440,23 @@ def prepare_inputs_for_phase_diagram(inputyamlfile, calculation_base_name=None):
400440 n_species_a = int (n_atoms - n_species_b )
401441 output_chemical_composition [other_element ] = n_species_a
402442
403- if n_species_a == 0 :
404- raise ValueError ("Please add pure phase as a new entry!" )
443+ #now we find temp ref composition
444+ if count > is_ref_count :
445+ temp_ref_count = count - 1
446+ temp_ref_comp = comp_arr [count - 1 ]
447+ elif count < is_ref_count :
448+ temp_ref_count = count + 1
449+ temp_ref_comp = comp_arr [count + 1 ]
450+
405451 #create input comp dict and output comp dict
406- input_chemical_composition = {element :number for element , number in zip (calc ['element' ],
407- calc ['composition' ]['number_of_atoms' ])}
452+ #now this depends on the previous composition
453+
454+ input_chemical_composition = created_comp_dicts [temp_ref_count ]
408455
409456 #good, now we need to write such a structure out; likely better to use working directory for that
410457 folder_prefix = f'{ phase_name } -{ comp :.2f} '
411- calc ['reference_composition' ] = comps ['reference' ]
412- #if solid, its very easy; kinda
413- #if calc['reference_phase'] == 'solid':
458+ calc ['reference_composition' ] = float (temp_ref_comp )
414459 if use_composition_scaling :
415- #this is solid , and comp scale is turned on
416- #pop extra keys which are not needed
417- #we dont kick out phase_name
418460 extra_keys = ['composition' , 'reference_phase' ]
419461 for key in extra_keys :
420462 _ = calc .pop (key , None )
@@ -423,39 +465,25 @@ def prepare_inputs_for_phase_diagram(inputyamlfile, calculation_base_name=None):
423465 #add ref phase, needed
424466 calc ['mode' ] = str ('composition_scaling' )
425467 calc ['folder_prefix' ] = folder_prefix
468+ calc ['lattice' ] = str (created_lattices [temp_ref_count ])
426469 calc ['composition_scaling' ] = {}
427470 calc ['composition_scaling' ]['output_chemical_composition' ] = output_chemical_composition
428471
429472 else :
430- #manually create a mixed structure - not that the pair style is always ok :)
431-
432- outfile = os .path .join (os .getcwd (), os .path .basename (calc ['lattice' ])+ folder_prefix + '.comp.mod' )
433- #print(f'finding comp trf from {input_chemical_composition} to {output_chemical_composition}')
434- #write_structure(calc['lattice'], input_chemical_composition, output_chemical_composition, outfile)
435-
436- simplecalc = SimpleCalculation (calc ['lattice' ],
437- calc ["element" ],
438- input_chemical_composition ,
439- output_chemical_composition )
440- compsc = CompositionTransformation (simplecalc , keep_types = True )
441- compsc .write_structure (outfile )
442-
443- #pop extra keys which are not needed
444- #we dont kick out phase name
445473 extra_keys = ['composition' ]
446474 for key in extra_keys :
447475 _ = calc .pop (key , None )
448476
449477 #add ref phase, needed
450478 calc ['mode' ] = str ('fe' )
451479 calc ['folder_prefix' ] = folder_prefix
452- calc ['lattice' ] = str ( outfile )
480+ calc ['lattice' ] = created_lattices [ count ]
453481
454- #now we need to run this for different temp
455- for temp in temp_arr :
456- calc_for_temp = copy .deepcopy (calc )
457- calc_for_temp ['temperature' ] = int (temp )
458- all_calculations .append (calc_for_temp )
482+ #now we need to run this for different temp
483+ for temp in temp_arr :
484+ calc_for_temp = copy .deepcopy (calc )
485+ calc_for_temp ['temperature' ] = int (temp )
486+ all_calculations .append (calc_for_temp )
459487
460488 #finish and write up the file
461489 output_data = {"calculations" : all_calculations }
0 commit comments