Skip to content

Commit

Permalink
Modify the conformer comparison logic for efficiency
Browse files Browse the repository at this point in the history
Save `fl_distance` and `dmat` to each of the `conformer` for efficient processing.
  • Loading branch information
JintaoWu98 committed Aug 20, 2024
1 parent b73acf1 commit a69b3c5
Showing 1 changed file with 40 additions and 7 deletions.
47 changes: 40 additions & 7 deletions arc/species/conformers.py
Original file line number Diff line number Diff line change
Expand Up @@ -519,15 +519,31 @@ def conformers_combinations_by_lowest_conformer(label, mol, base_xyz, multiple_t
newest_conformers_dict[tor] = list() # Keys are torsions for plotting.
for xyz, energy, dihedral in zip(xyzs, energies, sampling_points):
exists = False
if any([converter.compare_confs(xyz, conf['xyz']) for conf in new_conformers + newest_conformer_list]):
exists = True
dmat1, fl_distance1 = None, None
for conf in new_conformers + newest_conformer_list:
conf['dmat'] = conf.get('dmat')
conf['fl_distance'] = conf.get('fl_distance')
fl_distance1, fl_distance2, dmat1, dmat2 = converter.compare_confs_fl(xyz,conf['xyz'],
dmat2=conf['dmat'],
fl_distance2=conf['fl_distance'])
conf['fl_distance'] = fl_distance2 if conf['fl_distance'] is None else conf['fl_distance']
conf['dmat'] = dmat2 if conf['dmat'] is None else conf['dmat']
if dmat1 is None:
break
if converter.compare_confs(xyz, conf['xyz'],
skip_conversion=True,
dmat1=dmat1,dmat2=conf['dmat']):
exists = True
break
if xyz is not None and energy is not None:
conformer = {'index': len_conformers + len(new_conformers) + len(newest_conformer_list),
'xyz': xyz,
'FF energy': round(energy, 3),
'source': f'Changing dihedrals on most stable conformer, iteration {i}',
'torsion': tor,
'dihedral': round(dihedral, 2)}
'dihedral': round(dihedral, 2),
'dmat': dmat1 if dmat1 is not None else None,
'fl_distance': fl_distance1 if fl_distance1 is not None else None}
newest_conformers_dict[tor].append(conformer)
if not exists:
newest_conformer_list.append(conformer)
Expand All @@ -541,7 +557,9 @@ def conformers_combinations_by_lowest_conformer(label, mol, base_xyz, multiple_t
'FF energy': None,
'source': f'Changing dihedrals on most stable conformer, iteration {i}, but FF energy is None',
'torsion': tor,
'dihedral': round(dihedral, 2)})
'dihedral': round(dihedral, 2),
'dmat': dmat1 if dmat1 is not None else None,
'fl_distance': fl_distance1 if fl_distance1 is not None else None})
new_conformers.extend(newest_conformer_list)
if not newest_conformer_list:
newest_conformer_list = [lowest_conf_i]
Expand Down Expand Up @@ -1113,9 +1131,24 @@ def get_lowest_confs(label: str,
for index in range(len(conformer_list)):
if (e is not None and conformer_list[index][energy] > min_e + e) or (n is not None and len(lowest_confs) >= n):
break
if index > 0 and not any([converter.compare_confs(lowest_conf['xyz'], conformer_list[index]['xyz'])
for lowest_conf in lowest_confs]):
lowest_confs.append(conformer_list[index])
if index>0:
for lowest_conf in lowest_confs:
lowest_conf['dmat'] = lowest_conf.get('dmat')
lowest_conf['fl_distance'] = lowest_conf.get('fl_distance')
fl_distance1, fl_distance2, dmat1, dmat2 = converter.compare_confs_fl(conformer_list[index]['xyz'],
lowest_conf['xyz'],
dmat2=lowest_conf['dmat'],
fl_distance2=lowest_conf['fl_distance'])
lowest_conf['fl_distance'] = fl_distance2 if lowest_conf['fl_distance'] is None else lowest_conf['fl_distance']
lowest_conf['dmat'] = dmat2 if lowest_conf['dmat'] is None else lowest_conf['dmat']
if dmat1 is None:
lowest_confs.append(conformer_list[index])
break
if converter.compare_confs(conformer_list[index]['xyz'], lowest_conf['xyz'],
skip_conversion=True,
dmat1=dmat1,dmat2=lowest_conf['dmat']):
break
lowest_confs.append(conformer_list[index]) if lowest_conf==lowest_confs[-1] else None
return lowest_confs


Expand Down

0 comments on commit a69b3c5

Please sign in to comment.