Skip to content

Commit 793d977

Browse files
committed
merging pylibefp to qchem versions
1 parent 74e80fa commit 793d977

16 files changed

Lines changed: 365 additions & 256 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,6 @@ build*/
2929
comp*.log
3030
/lib
3131
.DS_Store
32+
__pycache__/
33+
*.pyc
34+
*.pyo
0 Bytes
Binary file not shown.
-3.25 KB
Binary file not shown.

lib/pylibefp/tests/test_efpefp.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_elec_1b():
4545

4646
def test_pol_1a():
4747
asdf = system_1()
48-
opts = {'elec': True, 'pol': True, 'elec_damp': 'screen'}
48+
opts = {'elec': True, 'pol': True, 'elec_damp': 'screen', 'print': 0}
4949
asdf.set_opts(opts)
5050
asdf.compute()
5151
ene = asdf.get_energy()
@@ -56,7 +56,7 @@ def test_pol_1a():
5656
expected_ene['elec'] = expected_ene['electrostatic'] = elec
5757
expected_ene['pol'] = expected_ene['polarization'] = pol
5858
expected_ene['total'] = elec + pol
59-
pprint.pprint(opts)
59+
#pprint.pprint(opts)
6060
assert compare_recursive(expected_ene, ene, atol=1.e-6, return_message=True), 'FAILED'
6161

6262

@@ -363,7 +363,9 @@ def test_total_4d():
363363
test_disp_1a, test_disp_1b, test_disp_2a, test_disp_2b, test_disp_3a, test_disp_3b,
364364
test_xr_1, test_xr_2, test_xr_3,
365365
test_total_1a, test_total_2a, test_total_3a, test_total_4a, test_total_4b, test_total_4c, test_total_4d]
366-
for f in function_list:
366+
tests = function_list
367+
#tests = [item for item in function_list if 'pol' in str(item)]
368+
for f in tests:
367369
print(f'\nComputing {f.__name__}')
368370
f()
369371

lib/pylibefp/tests/test_efpefp_new.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@ def frag_setup(test_name):
2525
efp.set_periodic_box(periodic_box)
2626
#print('box2', efp.get_periodic_box())
2727

28-
29-
3028
#print(frag_coords)
3129
#pprint.pprint(efp_options)
3230
efp.compute(do_gradient = if_gradient)
3331
ene = efp.get_energy()
3432

35-
if 'enable_pairwise' in efp_options.keys():
36-
if efp_options['enable_pairwise'] in [True, 'true', 1]:
37-
efp.print_pairwise_energies()
33+
# print pairwise components
34+
#if 'enable_pairwise' in efp_options.keys():
35+
# if efp_options['enable_pairwise'] in [True, 'true', 1]:
36+
# efp.print_pairwise_energies()
3837

3938
print(efp.energy_summary())
4039
if if_gradient:
@@ -50,9 +49,9 @@ def frag_setup(test_name):
5049
'symm_1.in', 'symm_2.in', 'symm_2full.in', 'symm_2pw.in']
5150

5251
# running for all tests in files list
53-
#for f in files:
54-
# print(f'\nComputing {f}...')
55-
# frag_setup('../'+f)
52+
for f in files:
53+
print(f'\nComputing {f}...')
54+
frag_setup('../'+f)
5655

5756
# single test execution
5857
frag_setup('../symm_2pw.in')

lib/pylibefp/wrapper.py

Lines changed: 129 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,6 @@ def add_potential(efpobj, potential, fragpath='LIBRARY', duplicates_ok=False):
143143
for lst in [paths, library_paths]:
144144
for spth in '/Users/lyuda/LIBEFP/libefp_skp_may2025/share/libefp/fraglib;/Users/lyuda/LIBEFP/libefp_skp_may2025/share/libefp/fraglib/databases'.split(';'):
145145
lst.append(spth)
146-
lst.append('/scratch/gilbreth/paulsk/ls_pylib/libefp/fraglib')
147146
#lst.append('/opt/anaconda1anaconda2anaconda3/share/libefp/fraglib')
148147
#lst.append('/opt/anaconda1anaconda2anaconda3/share/libefp/fraglib/databases')
149148
#lst.append('/opt/anaconda1anaconda2anaconda3/Library/share/libefp/fraglib')
@@ -292,7 +291,9 @@ def get_opts(efpobj, label='libefp'):
292291
core.EFP_DISP_DAMP_OFF: 'off',
293292
}[opts.disp_damp]
294293

294+
dopts['pol_damp_tt_value'] = opts.pol_damp_tt_value
295295
dopts['enable_pbc'] = bool(opts.enable_pbc)
296+
dopts['enable_elpot'] = bool(opts.enable_elpot)
296297
dopts['enable_cutoff'] = bool(opts.enable_cutoff)
297298
dopts['swf_cutoff'] = opts.swf_cutoff
298299
dopts['xr_cutoff'] = opts.xr_cutoff
@@ -351,8 +352,8 @@ def set_opts(efpobj, dopts, label='libefp', append='libefp'):
351352
"""
352353
# warn on stray dopts keys
353354
allowed = [
354-
'elec', 'pol', 'disp', 'xr', 'elec_damp', 'pol_damp', 'disp_damp', 'enable_pbc', 'enable_cutoff', 'swf_cutoff',
355-
'xr_cutoff',
355+
'elec', 'pol', 'disp', 'xr', 'elec_damp', 'pol_damp', 'disp_damp',
356+
'pol_damp_tt_value', 'enable_pbc', 'enable_elpot', 'enable_cutoff', 'swf_cutoff', 'xr_cutoff',
356357
'pol_driver', 'ai_elec', 'ai_pol', 'enable_pairwise', 'ligand', 'symmetry', 'symm_frag',
357358
'spec_elec', 'spec_pol', 'spec_disp', 'spec_xr', 'spec_chtr', 'ai_qq', 'qq', 'lj', 'special_fragment',
358359
'spec_qq', 'spec_lj', 'print'
@@ -374,6 +375,9 @@ def set_opts(efpobj, dopts, label='libefp', append='libefp'):
374375
#opts.terms |= core.efp_term.EFP_TERM_POL
375376
#opts.terms |= core.efp_term.EFP_TERM_DISP
376377
#opts.terms |= core.efp_term.EFP_TERM_XR
378+
opts.elec_damp = core.EFP_ELEC_DAMP_SCREEN
379+
opts.pol_damp = core.EFP_POL_DAMP_TT
380+
opts.disp_damp = core.EFP_DISP_DAMP_OVERLAP
377381
elif append == 'psi':
378382
opts.terms |= core.efp_term.EFP_TERM_ELEC
379383
opts.terms |= core.efp_term.EFP_TERM_POL
@@ -566,6 +570,16 @@ def set_opts(efpobj, dopts, label='libefp', append='libefp'):
566570
_result_to_error(core.efp_result.EFP_RESULT_SYNTAX_ERROR,
567571
'invalid value for [T/F] {}: {}'.format(topic, dopts[topic]))
568572

573+
topic = _lbtl[label].get('enable_elpot', 'enable_elpot')
574+
if topic in dopts:
575+
if dopts[topic] in trues:
576+
opts.enable_elpot = 1
577+
elif dopts[topic] in falses:
578+
opts.enable_elpot = 0
579+
else:
580+
_result_to_error(core.efp_result.EFP_RESULT_SYNTAX_ERROR,
581+
'invalid value for [T/F] {}: {}'.format(topic, dopts[topic]))
582+
569583
topic = _lbtl[label].get('symmetry', 'symmetry')
570584
if topic in dopts:
571585
if dopts[topic] in trues:
@@ -650,6 +664,12 @@ def set_opts(efpobj, dopts, label='libefp', append='libefp'):
650664
_result_to_error(core.efp_result.EFP_RESULT_SYNTAX_ERROR,
651665
'invalid value for [iterative/direct] {}: {}'.format(topic, dopts[topic]))
652666

667+
topic = _lbtl[label].get('pol_damp_tt_value', 'pol_damp_tt_value')
668+
if topic in dopts:
669+
opts.pol_damp_tt_value = float(dopts[topic])
670+
else:
671+
opts.pol_damp_tt_value = 0.6 # libefp default set in efpmd
672+
653673
topic = _lbtl[label].get('ai_elec', 'ai_elec')
654674
if topic in dopts:
655675
if dopts[topic] in trues:
@@ -898,109 +918,109 @@ def get_frag_count(efpobj):
898918

899919
return nfrag
900920

901-
902-
def get_multipole_count(efpobj):
903-
"""Gets the number of multipoles in `efpobj` computation.
904-
905-
Returns
906-
-------
907-
int
908-
Total number of multipoles from electrostatics calculation.
909-
910-
"""
911-
(res, nmult) = efpobj._efp_get_multipole_count()
912-
_result_to_error(res)
913-
914-
return nmult
915-
916-
917-
def get_multipole_coordinates(efpobj, verbose=1):
918-
"""Gets the coordinates of `efpobj` electrostatics multipoles.
919-
920-
Parameters
921-
----------
922-
verbose : int, optional
923-
Whether to print out the multipole coordinates. 0: no printing. 1:
924-
print charges and dipoles. 2: additionally print quadrupoles
925-
and octupoles.
926-
927-
Returns
928-
-------
929-
list
930-
``3 n_mult`` (flat) array of multipole locations.
931-
932-
Examples
933-
--------
934-
935-
>>> # Use with NumPy
936-
>>> n_mult = efpobj.get_multipole_count()
937-
>>> xyz_mult = np.asarray(efpobj.get_multipole_coordinates()).reshape(n_mult, 3)
938-
939-
"""
940-
nmult = efpobj.get_multipole_count()
941-
(res, xyz) = efpobj._efp_get_multipole_coordinates(nmult)
942-
_result_to_error(res)
943-
944-
if verbose >= 1:
945-
xyz3 = list(map(list, zip(*[iter(xyz)] * 3)))
946-
947-
text = '\n ==> EFP Multipole Coordinates <==\n\n'
948-
for mu in range(nmult):
949-
text += '{:6d} {:14.8f} {:14.8f} {:14.8f}\n'.format(mu, *xyz3[mu])
950-
print(text)
951-
952-
return xyz
953-
954-
955-
def get_multipole_values(efpobj, verbose=1):
956-
"""Gets the computed per-point multipoles of `efpobj`.
957-
958-
Parameters
959-
----------
960-
verbose : int, optional
961-
Whether to print out the multipole arrays. 0: no printing. 1:
962-
print charges and dipoles. ``2``: additionally print quadrupoles
963-
and octupoles.
964-
965-
Returns
966-
-------
967-
list
968-
``20 n_mult`` (flat) array of per-point multipole values including
969-
charges + dipoles + quadrupoles + octupoles.
970-
Dipoles stored as x, y, z.
971-
Quadrupoles stored as xx, yy, zz, xy, xz, yz.
972-
Octupoles stored as xxx, yyy, zzz, xxy, xxz, xyy, yyz, xzz, yzz, xyz.
973-
974-
Examples
975-
--------
976-
>>> # Use with NumPy
977-
>>> n_mult = efpobj.get_multipole_count()
978-
>>> val_mult = np.asarray(efpobj.get_multipole_values()).reshape(n_mult, 20)
979-
980-
"""
981-
nmult = efpobj.get_multipole_count()
982-
(res, mult) = efpobj._efp_get_multipole_values(nmult)
983-
_result_to_error(res)
984-
985-
if verbose >= 1:
986-
mult20 = list(map(list, zip(*[iter(mult)] * 20)))
987-
988-
text = '\n ==> EFP Multipoles: Charge & Dipole <==\n\n'
989-
for mu in range(nmult):
990-
text += '{:6d} {:14.8f} {:14.8f} {:14.8f} {:14.8f}\n'.format(mu, *mult20[mu][:4])
991-
992-
if verbose >= 2:
993-
text += '\n ==> EFP Multipoles: Quadrupole <==\n\n'
994-
for mu in range(nmult):
995-
text += '{:6d} {:12.6f} {:12.6f} {:12.6f} {:12.6f} {:12.6f} {:12.6f}\n'.format(mu, *mult20[mu][4:10])
996-
text += '\n ==> EFP Multipoles: Octupole <==\n\n'
997-
for mu in range(nmult):
998-
text += '{:6d} {:12.6f} {:12.6f} {:12.6f} {:12.6f} {:12.6f} {:12.6f} {:12.6f} {:12.6f} {:12.6f} {:12.6f}\n'.format(
999-
mu, *mult20[mu][10:])
1000-
print(text)
1001-
1002-
return mult
1003-
921+
# #
922+
# # def get_multipole_count(efpobj):
923+
# # """Gets the number of multipoles in `efpobj` computation.
924+
# #
925+
# # Returns
926+
# # -------
927+
# # int
928+
# # Total number of multipoles from electrostatics calculation.
929+
# #
930+
# # """
931+
# # (res, nmult) = efpobj._efp_get_multipole_count()
932+
# # _result_to_error(res)
933+
# #
934+
# # return nmult
935+
# #
936+
#
937+
# def get_multipole_coordinates(efpobj, verbose=1):
938+
# """Gets the coordinates of `efpobj` electrostatics multipoles.
939+
#
940+
# Parameters
941+
# ----------
942+
# verbose : int, optional
943+
# Whether to print out the multipole coordinates. 0: no printing. 1:
944+
# print charges and dipoles. 2: additionally print quadrupoles
945+
# and octupoles.
946+
#
947+
# Returns
948+
# -------
949+
# list
950+
# ``3 n_mult`` (flat) array of multipole locations.
951+
#
952+
# Examples
953+
# --------
954+
#
955+
# >>> # Use with NumPy
956+
# >>> n_mult = efpobj.get_multipole_count()
957+
# >>> xyz_mult = np.asarray(efpobj.get_multipole_coordinates()).reshape(n_mult, 3)
958+
#
959+
# """
960+
# nmult = efpobj.get_multipole_count()
961+
# (res, xyz) = efpobj._efp_get_multipole_coordinates(nmult)
962+
# _result_to_error(res)
963+
#
964+
# if verbose >= 1:
965+
# xyz3 = list(map(list, zip(*[iter(xyz)] * 3)))
966+
#
967+
# text = '\n ==> EFP Multipole Coordinates <==\n\n'
968+
# for mu in range(nmult):
969+
# text += '{:6d} {:14.8f} {:14.8f} {:14.8f}\n'.format(mu, *xyz3[mu])
970+
# print(text)
971+
#
972+
# return xyz
973+
#
974+
#
975+
# def get_multipole_values(efpobj, verbose=1):
976+
# """Gets the computed per-point multipoles of `efpobj`.
977+
#
978+
# Parameters
979+
# ----------
980+
# verbose : int, optional
981+
# Whether to print out the multipole arrays. 0: no printing. 1:
982+
# print charges and dipoles. ``2``: additionally print quadrupoles
983+
# and octupoles.
984+
#
985+
# Returns
986+
# -------
987+
# list
988+
# ``20 n_mult`` (flat) array of per-point multipole values including
989+
# charges + dipoles + quadrupoles + octupoles.
990+
# Dipoles stored as x, y, z.
991+
# Quadrupoles stored as xx, yy, zz, xy, xz, yz.
992+
# Octupoles stored as xxx, yyy, zzz, xxy, xxz, xyy, yyz, xzz, yzz, xyz.
993+
#
994+
# Examples
995+
# --------
996+
# >>> # Use with NumPy
997+
# >>> n_mult = efpobj.get_multipole_count()
998+
# >>> val_mult = np.asarray(efpobj.get_multipole_values()).reshape(n_mult, 20)
999+
#
1000+
# """
1001+
# nmult = efpobj.get_multipole_count()
1002+
# (res, mult) = efpobj._efp_get_multipole_values(nmult)
1003+
# _result_to_error(res)
1004+
#
1005+
# if verbose >= 1:
1006+
# mult20 = list(map(list, zip(*[iter(mult)] * 20)))
1007+
#
1008+
# text = '\n ==> EFP Multipoles: Charge & Dipole <==\n\n'
1009+
# for mu in range(nmult):
1010+
# text += '{:6d} {:14.8f} {:14.8f} {:14.8f} {:14.8f}\n'.format(mu, *mult20[mu][:4])
1011+
#
1012+
# if verbose >= 2:
1013+
# text += '\n ==> EFP Multipoles: Quadrupole <==\n\n'
1014+
# for mu in range(nmult):
1015+
# text += '{:6d} {:12.6f} {:12.6f} {:12.6f} {:12.6f} {:12.6f} {:12.6f}\n'.format(mu, *mult20[mu][4:10])
1016+
# text += '\n ==> EFP Multipoles: Octupole <==\n\n'
1017+
# for mu in range(nmult):
1018+
# text += '{:6d} {:12.6f} {:12.6f} {:12.6f} {:12.6f} {:12.6f} {:12.6f} {:12.6f} {:12.6f} {:12.6f} {:12.6f}\n'.format(
1019+
# mu, *mult20[mu][10:])
1020+
# print(text)
1021+
#
1022+
# return mult
1023+
#
10041024

10051025
def get_induced_dipole_count(efpobj):
10061026
"""Gets the number of polarization induced dipoles in `efpobj` computation.
@@ -1910,9 +1930,9 @@ def old_to_dict(efpobj):
19101930
core.efp.get_point_charge_count = get_point_charge_count
19111931
core.efp.get_point_charge_coordinates = get_point_charge_coordinates
19121932
core.efp.get_point_charge_values = get_point_charge_values
1913-
core.efp.get_multipole_count = get_multipole_count
1914-
core.efp.get_multipole_coordinates = get_multipole_coordinates
1915-
core.efp.get_multipole_values = get_multipole_values
1933+
#core.efp.get_multipole_count = get_multipole_count
1934+
#core.efp.get_multipole_coordinates = get_multipole_coordinates
1935+
#core.efp.get_multipole_values = get_multipole_values
19161936
core.efp.get_induced_dipole_count = get_induced_dipole_count
19171937
core.efp.get_induced_dipole_coordinates = get_induced_dipole_coordinates
19181938
core.efp.get_induced_dipole_values = get_induced_dipole_values

0 commit comments

Comments
 (0)