Skip to content

Commit

Permalink
Merge pull request #867 from panxiang126/devel
Browse files Browse the repository at this point in the history
Automatically set the relative atomic mass according to "type_map"
  • Loading branch information
AnguseZhang authored Aug 16, 2022
2 parents 2764c96 + c5d0d97 commit 544953e
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 10 deletions.
4 changes: 2 additions & 2 deletions dpgen/generator/arginfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ def run_mdata_arginfo() -> Argument:
# basics
def basic_args() -> List[Argument]:
doc_type_map = 'Atom types.'
doc_mass_map = 'Standard atom weights.'
doc_mass_map = 'Standard atomic weights (default: "auto"). if one want to use isotopes, or non-standard element names, chemical symbols, or atomic number in the type_map list, please customize the mass_map list instead of using "auto". Tips: at present the default value will not be applied automatically, so you need to set "mass_map" to "auto" manually in param.json.'
doc_use_ele_temp = 'Currently only support fp_style vasp. \n\n\
- 0: no electron temperature. \n\n\
- 1: eletron temperature as frame parameter. \n\n\
- 2: electron temperature as atom parameter.'

return [
Argument("type_map", list, optional=False, doc=doc_type_map),
Argument("mass_map", list, optional=False, doc=doc_mass_map),
Argument("mass_map", [str, list], optional=True, default="auto", doc=doc_mass_map),
Argument("use_ele_temp", int, optional=True,
default=0, doc=doc_use_ele_temp),
]
Expand Down
108 changes: 103 additions & 5 deletions dpgen/generator/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -968,7 +968,7 @@ def _make_model_devi_revmat(iter_index, jdata, mdata, conf_systems):
sys_idx = expand_idx(cur_job['sys_idx'])
if (len(sys_idx) != len(list(set(sys_idx)))) :
raise RuntimeError("system index should be uniq")
mass_map = jdata['mass_map']
mass_map = [get_atomic_masses(i) for i in jdata['type_map']] if jdata['mass_map'] == "auto" else jdata['mass_map']
use_plm = jdata.get('model_devi_plumed', False)
use_plm_path = jdata.get('model_devi_plumed_path', False)
trj_freq = _get_param_alias(cur_job, ['t_freq', 'trj_freq','traj_freq'])
Expand Down Expand Up @@ -1115,7 +1115,7 @@ def _make_model_devi_native(iter_index, jdata, mdata, conf_systems):
model_devi_taup = 0.5
if 'model_devi_taup' in jdata :
model_devi_taup = jdata['model_devi_taup']
mass_map = jdata['mass_map']
mass_map = [get_atomic_masses(i) for i in jdata['type_map']] if jdata['mass_map'] == "auto" else jdata['mass_map']
nopbc = jdata.get('model_devi_nopbc', False)

iter_name = make_iter_name(iter_index)
Expand Down Expand Up @@ -1237,7 +1237,7 @@ def _make_model_devi_native_gromacs(iter_index, jdata, mdata, conf_systems):
if (len(sys_idx) != len(list(set(sys_idx)))) :
raise RuntimeError("system index should be uniq")

mass_map = jdata['mass_map']
mass_map = [get_atomic_masses(i) for i in jdata['type_map']] if jdata['mass_map'] == "auto" else jdata['mass_map']

iter_name = make_iter_name(iter_index)
train_path = os.path.join(iter_name, train_name)
Expand Down Expand Up @@ -2588,7 +2588,8 @@ def make_fp_pwscf(iter_index,
sys_data['atom_masses'] = []
pps = []
for iii in sys_data['atom_names']:
sys_data['atom_masses'].append(jdata['mass_map'][jdata['type_map'].index(iii)])
mass_map = [get_atomic_masses(i) for i in jdata['type_map']] if jdata['mass_map'] == "auto" else jdata['mass_map']
sys_data['atom_masses'].append(mass_map[jdata['type_map'].index(iii)])
pps.append(fp_pp_files[jdata['type_map'].index(iii)])
ret = make_pwscf_input(sys_data, pps, fp_params, user_input = user_input)
with open('input', 'w') as fp:
Expand Down Expand Up @@ -2670,7 +2671,7 @@ def make_fp_abacus_scf(iter_index,
os.chdir(ii)
sys_data = dpdata.System('POSCAR').data
if 'mass_map' in jdata:
sys_data['atom_masses'] = jdata['mass_map']
sys_data['atom_masses'] = [get_atomic_masses(i) for i in jdata['type_map']] if jdata['mass_map'] == "auto" else jdata['mass_map']
with open('INPUT', 'w') as fp:
fp.write(ret_input)
if 'kspacing' not in fp_params.keys():
Expand Down Expand Up @@ -3733,6 +3734,103 @@ def run_iter (param_file, machine_file) :
raise RuntimeError ("unknown task %d, something wrong" % jj)
record_iter (record, ii, jj)

def get_atomic_masses(atom):
element_names = ['Hydrogen', 'Helium', 'Lithium', 'Beryllium', 'Boron', 'Carbon', 'Nitrogen',
'Oxygen', 'Fluorine', 'Neon', 'Sodium', 'Magnesium', 'Aluminium', 'Silicon',
'Phosphorus', 'Sulfur', 'Chlorine', 'Argon', 'Potassium', 'Calcium', 'Scandium',
'Titanium', 'Vanadium', 'Chromium', 'Manganese', 'Iron', 'Cobalt', 'Nickel',
'Copper', 'Zinc', 'Gallium', 'Germanium', 'Arsenic', 'Selenium', 'Bromine',
'Krypton', 'Rubidium', 'Strontium', 'Yttrium', 'Zirconium', 'Niobium',
'Molybdenum', 'Technetium', 'Ruthenium', 'Rhodium', 'Palladium', 'Silver',
'Cadmium', 'Indium', 'Tin', 'Antimony', 'Tellurium', 'Iodine', 'Xenon',
'Caesium', 'Barium', 'Lanthanum', 'Cerium', 'Praseodymium', 'Neodymium',
'Promethium', 'Samarium', 'Europium', 'Gadolinium', 'Terbium', 'Dysprosium',
'Holmium', 'Erbium', 'Thulium', 'Ytterbium', 'Lutetium', 'Hafnium', 'Tantalum',
'Tungsten', 'Rhenium', 'Osmium', 'Iridium', 'Platinum', 'Gold', 'Mercury',
'Thallium', 'Lead', 'Bismuth', 'Polonium', 'Astatine', 'Radon', 'Francium',
'Radium', 'Actinium', 'Thorium', 'Protactinium', 'Uranium', 'Neptunium',
'Plutonium', 'Americium', 'Curium', 'Berkelium', 'Californium', 'Einsteinium',
'Fermium', 'Mendelevium', 'Nobelium', 'Lawrencium', 'Rutherfordium', 'Dubnium',
'Seaborgium', 'Bohrium', 'Hassium', 'Meitnerium', 'Darmastadtium', 'Roentgenium',
'Copernicium', 'Nihonium', 'Flerovium', 'Moscovium', 'Livermorium', 'Tennessine',
'Oganesson']
chemical_symbols = ['H', 'He', 'Li', 'Be', 'B', 'C', 'N', 'O', 'F', 'Ne', 'Na', 'Mg', 'Al',
'Si', 'P', 'S', 'Cl', 'Ar', 'K', 'Ca', 'Sc', 'Ti', 'V', 'Cr', 'Mn', 'Fe',
'Co', 'Ni', 'Cu', 'Zn', 'Ga', 'Ge', 'As', 'Se', 'Br', 'Kr', 'Rb', 'Sr',
'Y', 'Zr', 'Nb', 'Mo', 'Tc', 'Ru', 'Rh', 'Pd', 'Ag', 'Cd', 'In', 'Sn',
'Sb', 'Te', 'I', 'Xe', 'Cs', 'Ba', 'La', 'Ce', 'Pr', 'Nd', 'Pm', 'Sm',
'Eu', 'Gd', 'Tb', 'Dy', 'Ho', 'Er', 'Tm', 'Yb', 'Lu', 'Hf', 'Ta', 'W',
'Re', 'Os', 'Ir', 'Pt', 'Au', 'Hg', 'Tl', 'Pb', 'Bi', 'Po', 'At', 'Rn',
'Fr', 'Ra', 'Ac', 'Th', 'Pa', 'U', 'Np', 'Pu', 'Am', 'Cm', 'Bk', 'Cf',
'Es', 'Fm', 'Md', 'No', 'Lr', 'Rf', 'Db', 'Sg', 'Bh', 'Hs', 'Mt', 'Ds',
'Rg', 'Cn', 'Nh', 'Fl', 'Mc', 'Lv', 'Ts', 'Og']
atomic_number = [ i+1 for i in range(len(chemical_symbols)) ]

# NIST Standard Reference Database 144
# URL: https://physics.nist.gov/cgi-bin/Compositions/stand_alone.pl?ele=&ascii=ascii&isotype=all
atomic_masses_common = [1.00782503223, 4.00260325413, 7.0160034366, 9.012183065, 11.00930536,
12.0, 14.00307400443, 15.99491461957, 18.99840316273, 19.9924401762,
22.989769282, 23.985041697, 26.98153853, 27.97692653465, 30.97376199842,
31.9720711744, 34.968852682, 39.9623831237, 38.9637064864, 39.962590863,
44.95590828, 47.94794198, 50.94395704, 51.94050623, 54.93804391,
55.93493633, 58.93319429, 57.93534241, 62.92959772, 63.92914201,
68.9255735, 73.921177761, 74.92159457, 79.9165218, 78.9183376, 83.9114977282,
84.9117897379, 87.9056125, 88.9058403, 89.9046977, 92.906373, 97.90540482,
96.9063667, 101.9043441, 102.905498, 105.9034804, 106.9050916, 113.90336509,
114.903878776, 119.90220163, 120.903812, 129.906222748, 126.9044719,
131.9041550856, 132.905451961, 137.905247, 138.9063563, 139.9054431,
140.9076576, 141.907729, 144.9127559, 151.9197397, 152.921238, 157.9241123,
158.9253547, 163.9291819, 164.9303288, 165.9302995, 168.9342179, 173.9388664,
174.9407752, 179.946557, 180.9479958, 183.95093092, 186.9557501, 191.961477,
192.9629216, 194.9647917, 196.96656879, 201.9706434, 204.9744278, 207.9766525,
208.9803991, 208.9824308, 209.9871479, 222.0175782, 223.019736, 226.0254103,
227.0277523, 232.0380558, 231.0358842, 238.0507884, 237.0481736, 244.0642053,
243.0613813, 247.0703541, 247.0703073, 251.0795886, 252.08298, 257.0951061,
258.0984315, 259.10103, 262.10961, 267.12179, 268.12567, 271.13393, 272.13826,
270.13429, 276.15159, 281.16451, 280.16514, 285.17712, 284.17873, 289.19042,
288.19274, 293.20449, 292.20746, 294.21392]
# IUPAC Technical Report
# doi:10.1515/pac-2015-0305
atomic_masses_2013 = [1.00784, 4.002602, 6.938, 9.0121831, 10.806, 12.0096, 14.00643, 15.99903,
18.99840316, 20.1797, 22.98976928, 24.304, 26.9815385, 28.084, 30.973762,
32.059, 35.446, 39.948, 39.0983, 40.078, 44.955908, 47.867, 50.9415, 51.9961,
54.938044, 55.845, 58.933194, 58.6934, 63.546, 65.38, 69.723, 72.63, 74.921595,
78.971, 79.901, 83.798, 85.4678, 87.62, 88.90584, 91.224, 92.90637, 95.95, None,
101.07, 102.9055, 106.42, 107.8682, 112.414, 114.818, 118.71, 121.76, 127.6,
126.90447, 131.293, 132.905452, 137.327, 138.90547, 140.116, 140.90766, 144.242,
None, 150.36, 151.964, 157.25, 158.92535, 162.5, 164.93033, 167.259, 168.93422,
173.054, 174.9668, 178.49, 180.94788, 183.84, 186.207, 190.23, 192.217, 195.084,
196.966569, 200.592, 204.382, 207.2, 208.9804, None, None, None, None, None, None,
232.0377, 231.03588, 238.02891, None, None, None, None, None, None, None, None,
None, None, None, None, None, None, None, None, None, None, None, None, None,
None, None, None, None, None]
# IUPAC Technical Report
# doi:10.1515/pac-2019-0603
atomic_masses_2021 = [1.00784, 4.002602, 6.938, 9.0121831, 10.806, 12.0096, 14.00643, 15.99903,
18.99840316, 20.1797, 22.98976928, 24.304, 26.9815384, 28.084, 30.973762,
32.059, 35.446, 39.792, 39.0983, 40.078, 44.955907, 47.867, 50.9415, 51.9961,
54.938043, 55.845, 58.933194, 58.6934, 63.546, 65.38, 69.723, 72.63, 74.921595,
78.971, 79.901, 83.798, 85.4678, 87.62, 88.905838, 91.224, 92.90637, 95.95,
None, 101.07, 102.90549, 106.42, 107.8682, 112.414, 114.818, 118.71, 121.76,
127.6, 126.90447, 131.293, 132.905452, 137.327, 138.90547, 140.116, 140.90766,
144.242, None, 150.36, 151.964, 157.25, 158.925354, 162.5, 164.930329, 167.259,
168.934219, 173.045, 174.9668, 178.486, 180.94788, 183.84, 186.207, 190.23,
192.217, 195.084, 196.96657, 200.592, 204.382, 206.14, 208.9804, None, None,
None, None, None, None, 232.0377, 231.03588, 238.02891, None, None, None,
None, None, None, None, None, None, None, None, None, None, None, None, None,
None, None, None, None, None, None, None, None, None, None]

atomic_masses = [atomic_masses_common[n] if i is None else i for n,i in enumerate(atomic_masses_2021)]

if atom in element_names:
return atomic_masses[element_names.index(atom)]
elif atom in chemical_symbols:
return atomic_masses[chemical_symbols.index(atom)]
elif atom in atomic_number:
return atomic_masses[atomic_number.index(atom)]
else:
raise RuntimeError('unknown atomic identifier', atom, 'if one want to use isotopes, or non-standard element names, chemical symbols, or atomic number in the type_map list, please customize the mass_map list instead of using "auto".')


def gen_run(args) :
if args.PARAM and args.MACHINE:
Expand Down
6 changes: 3 additions & 3 deletions dpgen/tools/relabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
sys.path.insert(0, os.path.join(os.path.dirname(os.path.realpath(__file__)), '..'))
from dpgen.generator.lib.pwscf import make_pwscf_input
from dpgen.generator.lib.siesta import make_siesta_input
from dpgen.generator.run import make_vasp_incar
from dpgen.generator.run import make_vasp_incar, get_atomic_masses
import dpdata

def get_lmp_info(input_file) :
Expand Down Expand Up @@ -87,8 +87,8 @@ def create_init_tasks(target_folder, param_file, output, fp_json, verbose = True
jdata = json.load(open(os.path.join(target_folder, param_file)))
fp_jdata = json.load(open(fp_json))
# fp settings
mass_map = jdata['mass_map']
type_map = jdata['type_map']
mass_map = [get_atomic_masses(i) for i in jdata['type_map']] if jdata['mass_map'] == "auto" else jdata['mass_map']
fp_style = fp_jdata['fp_style']
fp_pp_path = fp_jdata['fp_pp_path']
fp_pp_files = fp_jdata['fp_pp_files']
Expand Down Expand Up @@ -147,7 +147,7 @@ def create_tasks(target_folder, param_file, output, fp_json, verbose = True, num
os.chdir(target_folder)
sys = jdata['sys_configs']
# fp settings
mass_map = jdata['mass_map']
mass_map = [get_atomic_masses(i) for i in jdata['type_map']] if jdata['mass_map'] == "auto" else jdata['mass_map']
fp_style = fp_jdata['fp_style']
fp_pp_path = fp_jdata['fp_pp_path']
fp_pp_files = fp_jdata['fp_pp_files']
Expand Down

0 comments on commit 544953e

Please sign in to comment.