Skip to content

Feature/main menu (Sourcery refactored)#2

Open
sourcery-ai[bot] wants to merge 1 commit intofeature/main_menufrom
sourcery/feature/main_menu
Open

Feature/main menu (Sourcery refactored)#2
sourcery-ai[bot] wants to merge 1 commit intofeature/main_menufrom
sourcery/feature/main_menu

Conversation

@sourcery-ai
Copy link
Copy Markdown

@sourcery-ai sourcery-ai bot commented Dec 7, 2022

Pull Request #1 refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

NOTE: As code is pushed to the original Pull Request, Sourcery will
re-run and update (force-push) this Pull Request with new refactorings as
necessary. If Sourcery finds no refactorings at any point, this Pull Request
will be closed automatically.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the feature/main_menu branch, then run:

git fetch origin sourcery/feature/main_menu
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai bot requested a review from yipy0005 December 7, 2022 06:12
Comment on lines -36 to +37
if (pdb_line.split())[0] == "ATOM" or (pdb_line.split())[0] == "HETATM":
pdb_line_terms["RECORD TYPE"] = pdb_line[0:6].replace(" ", "")
if (pdb_line.split())[0] in ["ATOM", "HETATM"]:
pdb_line_terms["RECORD TYPE"] = pdb_line[:6].replace(" ", "")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_pdb_line_components refactored with the following changes:

pdb_line_components["RECORD TYPE"] == "ATOM"
or pdb_line_components["RECORD TYPE"] == "HETATM"
):
if pdb_line_components["RECORD TYPE"] in ["ATOM", "HETATM"]:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function assemble_pdb_line_components refactored with the following changes:

Comment on lines -173 to +170
for key in pdb_line_terms.keys()
for key in pdb_line_terms
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_missing_terms refactored with the following changes:

Comment on lines -74 to +81
complex_lines: list[str] = []
with open(f"{root_dir}/{protein_pdb}_processed.gro", "r") as protein_f:
protein_lines = protein_f.readlines()
with open(
f"{root_dir}/{ligand_id}_fix.acpype/{ligand_id}_fix_GMX.gro", "r"
) as ligand_f:
ligand_lines = ligand_f.readlines()
for line in protein_lines[2:-1]:
complex_lines.append(line)
for line in ligand_lines[2:-1]:
complex_lines.append(line)
complex_lines: list[str] = list(protein_lines[2:-1])
complex_lines.extend(iter(ligand_lines[2:-1]))
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function combine_prot_lig_gro refactored with the following changes:

Comment on lines -193 to +284
default_params_for_ions_and_em: Dict[str, Any] = {
"integrator": self.integrator,
"nsteps": self.nsteps,
"emtol": self.emtol,
"emstep": self.emstep,
"cutoff_scheme": self.cutoff_scheme,
"nstlist": self.nstlist,
"pbc": self.pbc,
"ns_type": self.ns_type,
"rlist": self.rlist,
"coulombtype": self.coulombtype,
"rcoulomb": self.rcoulomb,
"rvdw": self.rvdw,
}

default_params_for_nvt_npt_md: Dict[str, Any] = {
"integrator": self.integrator,
"dt": self.dt,
"nsteps": self.nsteps,
"nstlog": self.nstlog,
"nstenergy": self.nstenergy,
"nstxout_compressed": self.nstxout_compressed,
"cutoff_scheme": self.cutoff_scheme,
"nstlist": self.nstlist,
"pbc": self.pbc,
"ns_type": self.ns_type,
"rlist": self.rlist,
"coulombtype": self.coulombtype,
"rcoulomb": self.rcoulomb,
"vdwtype": self.vdwtype,
"vdw_modifier": self.vdw_modifier,
"rvdw_switch": self.rvdw_switch,
"rvdw": self.rvdw,
"DispCorr": self.DispCorr,
"fourierspacing": self.fourierspacing,
"pme_order": self.pme_order,
"tcoupl": self.tcoupl,
"tc_grps": self.tc_grps,
"tau_t": self.tau_t,
"ref_t": self.ref_t,
"pcoupl": self.pcoupl,
"gen_vel": self.gen_vel,
"constraints": self.constraints,
"constraint_algorithm": self.constraint_algorithm,
"continuation": self.continuation,
"lincs_order": self.lincs_order,
"lincs_iter": self.lincs_iter,
}

if self.sim_type in sim_types and self.sim_type == "ions":
return default_params_for_ions_and_em

elif self.sim_type in sim_types and self.sim_type == "em":

additional_params: Dict[str, Any] = {
if self.sim_type in sim_types:
default_params_for_ions_and_em: Dict[str, Any] = {
"integrator": self.integrator,
"nsteps": self.nsteps,
"emtol": self.emtol,
"emstep": self.emstep,
"cutoff_scheme": self.cutoff_scheme,
"nstlist": self.nstlist,
"pbc": self.pbc,
"ns_type": self.ns_type,
"rlist": self.rlist,
"coulombtype": self.coulombtype,
"rcoulomb": self.rcoulomb,
"rvdw": self.rvdw,
}

default_params_for_nvt_npt_md: Dict[str, Any] = {
"integrator": self.integrator,
"dt": self.dt,
"nsteps": self.nsteps,
"nstlog": self.nstlog,
"nstenergy": self.nstenergy,
"nstxout_compressed": self.nstxout_compressed,
"cutoff_scheme": self.cutoff_scheme,
"nstlist": self.nstlist,
"pbc": self.pbc,
"ns_type": self.ns_type,
"rlist": self.rlist,
"coulombtype": self.coulombtype,
"rcoulomb": self.rcoulomb,
"vdwtype": self.vdwtype,
"vdw_modifier": self.vdw_modifier,
"rvdw_switch": self.rvdw_switch,
"rvdw": self.rvdw,
"DispCorr": self.DispCorr,
"fourierspacing": self.fourierspacing,
"pme_order": self.pme_order,
"tcoupl": self.tcoupl,
"tc_grps": self.tc_grps,
"tau_t": self.tau_t,
"ref_t": self.ref_t,
"pcoupl": self.pcoupl,
"gen_vel": self.gen_vel,
"constraints": self.constraints,
"constraint_algorithm": self.constraint_algorithm,
"continuation": self.continuation,
"lincs_order": self.lincs_order,
"lincs_iter": self.lincs_iter,
}

return default_params_for_ions_and_em | additional_params # type: ignore

elif self.sim_type in sim_types and self.sim_type == "nvt":
additional_params: Dict[str, Any] = {
"define": self.define,
"gen_temp": self.gen_temp,
"gen_seed": self.gen_seed,
}

return default_params_for_nvt_npt_md | additional_params # type: ignore

elif self.sim_type in sim_types and self.sim_type == "npt":
additional_params: Dict[str, Any] = {
"define": self.define,
"pcoupltype": self.pcoupltype,
"tau_p": self.tau_p,
"compressibility": self.compressibility,
"ref_p": self.ref_p,
"refcoord_scaling": self.refcoord_scaling,
}

return default_params_for_nvt_npt_md | additional_params # type: ignore

elif self.sim_type in sim_types and self.sim_type == "md":
additional_params: Dict[str, Any] = {
"pcoupltype": self.pcoupltype,
"tau_p": self.tau_p,
"compressibility": self.compressibility,
"ref_p": self.ref_p,
# "freezegrps": self.freezegrps,
# "freezedim": self.freezedim,
}

return default_params_for_nvt_npt_md | additional_params # type: ignore
if self.sim_type == "em":
additional_params: Dict[str, Any] = {
"vdwtype": self.vdwtype,
"vdw_modifier": self.vdw_modifier,
"rvdw_switch": self.rvdw_switch,
"DispCorr": self.DispCorr,
}

return default_params_for_ions_and_em | additional_params # type: ignore

elif self.sim_type == "ions":
return default_params_for_ions_and_em

elif self.sim_type == "md":
additional_params: Dict[str, Any] = {
"pcoupltype": self.pcoupltype,
"tau_p": self.tau_p,
"compressibility": self.compressibility,
"ref_p": self.ref_p,
# "freezegrps": self.freezegrps,
# "freezedim": self.freezedim,
}

return default_params_for_nvt_npt_md | additional_params # type: ignore

elif self.sim_type == "npt":
additional_params: Dict[str, Any] = {
"define": self.define,
"pcoupltype": self.pcoupltype,
"tau_p": self.tau_p,
"compressibility": self.compressibility,
"ref_p": self.ref_p,
"refcoord_scaling": self.refcoord_scaling,
}

return default_params_for_nvt_npt_md | additional_params # type: ignore

elif self.sim_type == "nvt":
additional_params: Dict[str, Any] = {
"define": self.define,
"gen_temp": self.gen_temp,
"gen_seed": self.gen_seed,
}

return default_params_for_nvt_npt_md | additional_params # type: ignore
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MDP.write_mdp_file refactored with the following changes:

Comment on lines -149 to +147
key_missing_numbers.append(int("0"))
key_missing_numbers.append(int("9999"))

key_missing_numbers.extend((int("0"), int("9999")))
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function checkConsecutive refactored with the following changes:

Comment on lines -158 to +164
if first_line != "":
if first_line in lines_lst[line_idx]:
output_lst.append(lines_lst[line_idx])
try:
while len(lines_lst[line_idx]) != 0:
line_idx += 1
if len(lines_lst[line_idx]) != 0:
output_lst.append(lines_lst[line_idx])
else:
break
except IndexError:
pass
if first_line != "" and first_line in lines_lst[line_idx]:
output_lst.append(lines_lst[line_idx])
try:
while len(lines_lst[line_idx]) != 0:
line_idx += 1
if len(lines_lst[line_idx]) != 0:
output_lst.append(lines_lst[line_idx])
else:
break
except IndexError:
pass
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function get_lines refactored with the following changes:

Comment on lines -212 to +207
if pdb_type == "COMPLEX" or pdb_type == "PROTEIN":
if pdb_type in {"COMPLEX", "PROTEIN"}:
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function read_topol refactored with the following changes:

Comment on lines -281 to +275
lig_itp_contents = lines[0:1] + lines[10:]

return lig_itp_contents
return lines[:1] + lines[10:]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function write_prm_file refactored with the following changes:

Comment on lines -328 to +321
else:
count = 0
for item in resname_lst:
if item in amino_acids_3_letter_codes:
count += 1
if count == 0:
return "LIGAND"
else:
return "COMPLEX"
count = sum(item in amino_acids_3_letter_codes for item in resname_lst)
return "LIGAND" if count == 0 else "COMPLEX"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function check_pdb_type refactored with the following changes:

@sourcery-ai
Copy link
Copy Markdown
Author

sourcery-ai bot commented Dec 7, 2022

Sourcery Code Quality Report

✅  Merging this PR will increase code quality in the affected files by 3.36%.

Quality metrics Before After Change
Complexity 21.61 😞 17.21 🙂 -4.40 👍
Method Length 135.15 😞 131.51 😞 -3.64 👍
Working memory 11.55 😞 11.33 😞 -0.22 👍
Quality 44.68% 😞 48.04% 😞 3.36% 👍
Other metrics Before After Change
Lines 1541 1481 -60
Changed files Quality Before Quality After Quality Change
src/check_pdb.py 39.86% 😞 41.57% 😞 1.71% 👍
src/gmx_ops.py 66.25% 🙂 67.38% 🙂 1.13% 👍
src/main_BAK.py 22.69% ⛔ 22.95% ⛔ 0.26% 👍
src/protprep.py 45.33% 😞 55.16% 🙂 9.83% 👍
src/utils.py 58.35% 🙂 61.33% 🙂 2.98% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
src/main_BAK.py main 46 ⛔ 954 ⛔ 19 ⛔ 8.76% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
src/check_pdb.py get_pdb_line_components 32 😞 558 ⛔ 11 😞 23.30% ⛔ Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
src/main_BAK.py mdp_type 20 😞 361 ⛔ 13 😞 28.57% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
src/protprep.py get_bound_ligand 23 😞 232 ⛔ 14 😞 29.72% 😞 Refactor to reduce nesting. Try splitting into smaller methods. Extract out complex expressions
src/check_pdb.py assemble_pdb_line_components 5 ⭐ 167 😞 30 ⛔ 40.73% 😞 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants