Skip to content

Commit

Permalink
Merge pull request #975 from haddocking/flexseg-onthefly-nfle
Browse files Browse the repository at this point in the history
Simplify definition of counted parameters by computing them on the fly from definition.
  • Loading branch information
VGPReys authored Sep 23, 2024
2 parents 64d625b + 76427b9 commit c6b3f99
Show file tree
Hide file tree
Showing 28 changed files with 307 additions and 198 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,7 @@ mdsteps_cool1 = 5000
mdsteps_cool2 = 10000
mdsteps_cool3 = 10000
ambig_fname = "data/ambig.tbl"
# give full flexibilit to the glycan
nfle = 1
# give full flexibility to the glycan
fle_sta_1 = 1
fle_end_1 = 4
fle_seg_1 = "B"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,7 @@ mdsteps_cool1 = 5000
mdsteps_cool2 = 10000
mdsteps_cool3 = 10000
ambig_fname = "data/ambig.tbl"
# give full flexibilit to the glycan
nfle = 1
# give full flexibility to the glycan
fle_sta_1 = 1
fle_end_1 = 4
fle_seg_1 = "B"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ ambig_fname = "data/1qu9_whiscy_air.tbl"
sampling = 2000
# Define CNS restraints between molecules
ncs_on = true
numncs = 2
ncs_sta1_1=2
ncs_end1_1=128
ncs_seg1_1="A"
Expand All @@ -56,7 +55,6 @@ ncs_end2_2=128
ncs_seg2_2="C"
# Define C3 symmetry restraints
sym_on = true
numc3sym = 1
c3sym_sta1_1=2
c3sym_end1_1=128
c3sym_seg1_1="A"
Expand All @@ -79,7 +77,6 @@ tolerance = 5
ambig_fname = "data/1qu9_whiscy_air.tbl"
# Define NCS restraints between molecules
ncs_on = true
numncs = 2
ncs_sta1_1=2
ncs_end1_1=128
ncs_seg1_1="A"
Expand All @@ -94,7 +91,6 @@ ncs_end2_2=128
ncs_seg2_2="C"
# Define C3 symmetry restraints
sym_on = true
numc3sym = 1
c3sym_sta1_1=2
c3sym_end1_1=128
c3sym_seg1_1="A"
Expand All @@ -113,7 +109,6 @@ tolerance = 5
ambig_fname = "data/1qu9_whiscy_air.tbl"
# Define NCS restraints between molecules
ncs_on = true
numncs = 2
ncs_sta1_1=2
ncs_end1_1=128
ncs_seg1_1="A"
Expand All @@ -128,7 +123,6 @@ ncs_end2_2=128
ncs_seg2_2="C"
# Define C3 symmetry restraints
sym_on = true
numc3sym = 1
c3sym_sta1_1=2
c3sym_end1_1=128
c3sym_seg1_1="A"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ ambig_fname = "data/1qu9_whiscy_air.tbl"
sampling = 20
# Define NCS restraints between molecules
ncs_on = true
numncs = 2
ncs_sta1_1=2
ncs_end1_1=128
ncs_seg1_1="A"
Expand All @@ -51,7 +50,6 @@ ncs_end2_2=128
ncs_seg2_2="C"
# Define C3 symmetry restraints
sym_on = true
numc3sym = 1
c3sym_sta1_1=2
c3sym_end1_1=128
c3sym_seg1_1="A"
Expand All @@ -74,7 +72,6 @@ tolerance = 20
ambig_fname = "data/1qu9_whiscy_air.tbl"
# Define NCS restraints between molecules
ncs_on = true
numncs = 2
ncs_sta1_1=2
ncs_end1_1=128
ncs_seg1_1="A"
Expand All @@ -89,7 +86,6 @@ ncs_end2_2=128
ncs_seg2_2="C"
# Define C3 symmetry restraints
sym_on = true
numc3sym = 1
c3sym_sta1_1=2
c3sym_end1_1=128
c3sym_seg1_1="A"
Expand All @@ -108,7 +104,6 @@ tolerance = 20
ambig_fname = "data/1qu9_whiscy_air.tbl"
# Define NCS restraints between molecules
ncs_on = true
numncs = 2
ncs_sta1_1=2
ncs_end1_1=128
ncs_seg1_1="A"
Expand All @@ -123,7 +118,6 @@ ncs_end2_2=128
ncs_seg2_2="C"
# Define C3 symmetry restraints
sym_on = true
numc3sym = 1
c3sym_sta1_1=2
c3sym_end1_1=128
c3sym_seg1_1="A"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ reference_fname = "data/1nx1_refe.pdb"
tolerance = 5
ambig_fname = "data/ambig.tbl"
# Define peptide as fully flexible
nfle = 1
fle_sta_1 = 1
fle_end_1 = 11
fle_seg_1 = "B"
Expand All @@ -72,7 +71,6 @@ reference_fname = "data/1nx1_refe.pdb"
tolerance = 5
ambig_fname = "data/ambig.tbl"
# Define peptide as fully flexible
nfle = 1
fle_sta_1 = 1
fle_end_1 = 11
fle_seg_1 = "B"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ select = 400
tolerance = 5
ambig_fname = "data/ambig.tbl"
# Define peptide as fully flexible
nfle = 1
fle_sta_1 = 1
fle_end_1 = 11
fle_seg_1 = "B"
Expand All @@ -65,7 +64,6 @@ reference_fname = "data/1nx1_refe.pdb"
tolerance = 5
ambig_fname = "data/ambig.tbl"
# Define peptide as fully flexible
nfle = 1
fle_sta_1 = 1
fle_end_1 = 11
fle_seg_1 = "B"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ select = 400
tolerance = 5
ambig_fname = "data/ambig.tbl"
# Define peptide as fully flexible
nfle = 1
fle_sta_1 = 1
fle_end_1 = 11
fle_seg_1 = "B"
Expand All @@ -65,7 +64,6 @@ reference_fname = "data/1nx1_refe.pdb"
tolerance = 5
ambig_fname = "data/ambig.tbl"
# Define peptide as fully flexible
nfle = 1
fle_sta_1 = 1
fle_end_1 = 11
fle_seg_1 = "B"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ select = 5
tolerance = 20
ambig_fname = "data/ambig.tbl"
# Define peptide as fully flexible
nfle = 1
fle_sta_1 = 1
fle_end_1 = 11
fle_seg_1 = "B"
Expand All @@ -60,7 +59,6 @@ reference_fname = "data/1nx1_refe.pdb"
tolerance = 20
ambig_fname = "data/ambig.tbl"
# Define peptide as fully flexible
nfle = 1
fle_sta_1 = 1
fle_end_1 = 11
fle_seg_1 = "B"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ select = 5
tolerance = 20
ambig_fname = "data/ambig.tbl"
# Define peptide as fully flexible
nfle = 2
fle_sta_1 = 1
fle_end_1 = 5
fle_seg_1 = "B"
Expand All @@ -63,7 +62,6 @@ reference_fname = "data/1nx1_refe.pdb"
tolerance = 20
ambig_fname = "data/ambig.tbl"
# Define peptide as fully flexible
nfle = 1
fle_sta_1 = 1
fle_end_1 = 11
fle_seg_1 = "B"
Expand Down
29 changes: 19 additions & 10 deletions src/haddock/gear/expandable_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@
# common error messages
_emsg_num_differ = (
"The parameter block {!r} expects "
"{} parameters, but {} are present "
"in the user configuration file: {}."
"{} parameters ({}), but {} are present "
"in the user configuration file: {}. "
"Parameter(s) {} are missing."
)


Expand Down Expand Up @@ -249,7 +250,7 @@ def _read_groups_in_user_config(
extract_params: Callable[..., set[str]],
_emsg_no_group: str = "Parameter block is not a valid expandable group",
_emsg_unexpected_params: str = "Unexpected params for group",
) -> set[str]:
) -> tuple[set[str], dict[str, int]]:
"""
Read groups in user config.
Expand Down Expand Up @@ -279,15 +280,18 @@ def _read_groups_in_user_config(
Returns
-------
set
new : set[str]
A set with the new parameters in the user configuration file
that are acceptable according to the expandable rules.
param_name_counts : dict[str, int]
Count of expendable parameter parameter names
"""
# minimum=1 is used to capture groups with missing parameters
user_groups = get_user_groups(user_config, minimum=1, reference=False)
default_group_names = set(group[0] for group in default_groups)

new: set[str] = set()
param_name_counts: dict[str, int] = {}
for (param_name, group_idx), params in user_groups.items():
if param_name not in default_group_names:
emsg = _emsg_no_group.format(param_name, group_idx)
Expand All @@ -311,35 +315,40 @@ def _read_groups_in_user_config(
# when num_found > num_expected the error about in `diff` is
# triggered instead
if num_found != num_expected:
expected_missings = set(expected_params).difference(params)
emsg = _emsg_num_differ.format(
param_name,
num_expected,
", ".join(expected_params),
num_found,
", ".join(params),
", ".join([f"`{p}`" for p in expected_missings]),
)
raise ConfigurationError(emsg)

related_params = extract_params(user_config, param_name, group_idx)
# Increment counts for this parameter
if related_params:
param_name_counts.setdefault(param_name, 0)
param_name_counts[param_name] += 1
new.update(related_params)

return new
return new, param_name_counts


def read_simplest_expandable(
expparams: Iterable[str], config: Iterable[str]
config: Iterable[str], expparams: Iterable[str],
) -> set[str]:
"""
Read expandable parameters from config file of the type `param_1`.
Parameters
----------
config : dict, dict.keys, set, or alike
The user configuration file.
expparams : dict, dict.keys, set, or alike
The parameter names that should be considered as expandable.
Usually, this is a module subdictionary of `type_simplest_ep`.
config : dict, dict.keys, set, or alike
The user configuration file.
Returns
-------
set of str
Expand Down
55 changes: 37 additions & 18 deletions src/haddock/gear/prepare_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -799,18 +799,18 @@ def validate_ncs_params(params: dict) -> None:
# Validate value of `numncs`
ncs_suffixes = list(groupped_ncs.keys())
# Case when number of definition do not match
if params["numncs"] != len(ncs_suffixes):
if params["nncs"] != len(ncs_suffixes):
msg = (
f'Number of NCS restraints (`numncs = {params["numncs"]}`) '
f'Number of NCS restraints (`nncs = {params["nncs"]}`) '
" do not match with the number of defined NCS restraints "
f"({len(ncs_suffixes)})"
)
error_list.append(msg)
else:
# Case when numbers do not match
if max(ncs_suffixes) != params["numncs"]:
if max(ncs_suffixes) != params["nncs"]:
msg = (
f'Number of NCS restraints (`numncs = {params["numncs"]}`) '
f'Number of NCS restraints (`nncs = {params["nncs"]}`) '
" do not match with the number of defined NCS restraints "
f"({', '.join([str(s) for s in ncs_suffixes])})"
)
Expand Down Expand Up @@ -1162,25 +1162,44 @@ def get_expandable_parameters(
def _get_expandable(
user_config: ParamMap, defaults: ParamMap, module_name: str, max_mols: int
) -> set[str]:
type_1 = get_single_index_groups(defaults)
type_2 = get_multiple_index_groups(defaults)
type_4 = get_mol_parameters(defaults)

# Set parsing vars
allowed_params: set[str] = set()
allowed_params.update(
read_single_idx_groups_user_config(user_config, type_1)
) # noqa: E501
allowed_params.update(
read_multiple_idx_groups_user_config(user_config, type_2)
) # noqa: E501
all_counts: dict[str, int] = {}
# Read single indexed groups (terminating by `_X`)
news_t1, counts_t1 = read_single_idx_groups_user_config(
user_config,
get_single_index_groups(defaults),
)
allowed_params.update(news_t1)
all_counts.update(counts_t1)
# Read multiple indexed groups (terminating by `_X_Y`)
news_t2, counts_t2 = read_multiple_idx_groups_user_config(
user_config,
get_multiple_index_groups(defaults),
)
allowed_params.update(news_t2)
all_counts.update(counts_t2)

with suppress(KeyError):
type_3 = type_simplest_ep[get_module_name(module_name)]
allowed_params.update(read_simplest_expandable(type_3, user_config))

_ = read_mol_parameters(user_config, type_4, max_mols=max_mols)
news_t3 = read_simplest_expandable(
user_config,
type_simplest_ep[get_module_name(module_name)],
)
allowed_params.update(news_t3)
# Read molecule paramters (starting by `mol_`)
_ = read_mol_parameters(
user_config,
get_mol_parameters(defaults),
max_mols=max_mols,
)
allowed_params.update(_)

# Add counted parameters to hidden user parameters
for param, count in all_counts.items():
count_param_name = f"n{param}"
if count_param_name in defaults.keys():
user_config[count_param_name] = count
# Return new set of allowed parameters
return allowed_params


Expand Down
14 changes: 7 additions & 7 deletions src/haddock/modules/refinement/emref/cns/emref.cns
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,17 @@ evaluate ($data.kcont=$kcont)
! NCS restraints
evaluate ($data.kncs = $kncs)
evaluate ($Data.flags.ncs = $ncs_on)
evaluate ($data.numncs = $numncs)
evaluate ($data.nncs = $nncs)

! Symmetry restraints
evaluate ($data.ksym = $ksym)
evaluate ($Data.flags.sym = $sym_on)
evaluate ($data.numc2sym = $numc2sym)
evaluate ($data.numc3sym = $numc3sym)
evaluate ($data.nums3sym = $nums3sym)
evaluate ($data.numc4sym = $numc4sym)
evaluate ($data.numc5sym = $numc5sym)
evaluate ($data.numc6sym = $numc6sym)
evaluate ($data.nc2sym = $nc2sym)
evaluate ($data.nc3sym = $nc3sym)
evaluate ($data.ns3sym = $ns3sym)
evaluate ($data.nc4sym = $nc4sym)
evaluate ($data.nc5sym = $nc5sym)
evaluate ($data.nc6sym = $nc6sym)

!Dihedral angle energy term:
evaluate ($data.flags.dihed = true)
Expand Down
Loading

0 comments on commit c6b3f99

Please sign in to comment.