Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop class name analogies favoring technical names #21

Merged
merged 16 commits into from
Jul 13, 2021
Merged

Drop class name analogies favoring technical names #21

merged 16 commits into from
Jul 13, 2021

Conversation

rvhonorato
Copy link
Member

This is a boring PR to make the code more accessible.

I do believe analogy is a great technique to match unrelated objects in order facilitate understanding and it is seen in many large projects out there in the wild. However me and @joaomcteixeira are getting lost in the ones that were present here since they were often actually quite metaphoric.

Additionally, since we aim the project to have a wide reach, we need to also consider code accessibility and making it more boring can increase its readability. There will still be plenty of room for creative expression later on :)

With this PR I also linted to code to comply with E501.
In this branch there are no tests yet, so I tested it by running the examples and checking if things were working.

"trans_vector_48": data_path / "toppar/initial_positions/trans_vector_48",
"trans_vector_49": data_path / "toppar/initial_positions/trans_vector_49",
"trans_vector_50": data_path / "toppar/initial_positions/trans_vector_50"
"trans_vector_0": (data_path /
Copy link
Member

Choose a reason for hiding this comment

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

This is a classic example where I would not personally follow strict 80-lenght line except if committing a major number of lines is intended in order to inflate statistics.

Copy link
Member

Choose a reason for hiding this comment

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

agreed. it actually reads better with single lines despite going over 80 chars which I like so much. Nonetheless what about:

  1. use Path and not /.
  2. Don't overload operators 😉
TRANSLATION_VECTORS = {
    f"trans_vector_{i}": Path(data_path, 'toppar', 'initial_positions', f'trans_vector_{i}')
    for i in range(51)
    }

Copy link
Member Author

Choose a reason for hiding this comment

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

ooh this is great @joaomcteixeira, thanks!

@@ -27,34 +27,43 @@ def run(self, module_information):
self.patch_defaults(module_information)

# Get the models generated in previous step
models_to_score = [p for p in self.previous_io.output if p.file_type == Format.PDB]
Copy link
Member

Choose a reason for hiding this comment

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

List comprehension is faster and IMHO more readable here.

Copy link
Member

Choose a reason for hiding this comment

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

I agree. please keep the list comprehension.


# Check if multiple models are provided
if len(models_to_score) > 1:
self.finish_with_error("Only one model allowed in LightDock sampling module")
self.finish_with_error("Only one model allowed in LightDock"
Copy link
Member

Choose a reason for hiding this comment

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

Same non-sense 80-length limitation. Luckily, not using old screens anymore.

Copy link
Member

Choose a reason for hiding this comment

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

in these cases if you really don't wanna go over 80 I advise writing:

_msg = "blablabla"
self.finish_with_error(_msg)

or

self.finish_with_error(
    "blablablabla 1"
    "blablabbla 2"
    )

expected = []
not_found = []
for model in models:
model_name = model.stem
if not (processed_pdb := self.path / f"{model_name}_haddock.{Format.PDB}").is_file():
Copy link
Member

Choose a reason for hiding this comment

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

Why this? Using modern Python and walrus operator is not a crime...

@@ -29,7 +30,9 @@ def __init__(self, file_name, file_type, path='.'):
self.path = str(Path(path).parent.absolute())

def __repr__(self):
return f"[{self.file_type}|{self.created}] {Path(self.path) / self.file_name}"
rep = (f"[{self.file_type}|{self.created}] "
Copy link
Member

Choose a reason for hiding this comment

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

Less efficient and unnecessary.

step.execute()


class Recipe:
Copy link
Member

Choose a reason for hiding this comment

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

If not using metaphors anymore, maybe there is a better name for this class too?

Copy link
Member

@brianjimenez brianjimenez left a comment

Choose a reason for hiding this comment

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

Boring review too. I am not a fan of strict linting, specially of line-length rules, but your call. List comprehensions and walrus operator are more pythonic options though.

Copy link
Member

@joaomcteixeira joaomcteixeira left a comment

Choose a reason for hiding this comment

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

Just made general comments. Nothing critical. Somethings I personally dislike, but they are not mistakes either.

"trans_vector_48": data_path / "toppar/initial_positions/trans_vector_48",
"trans_vector_49": data_path / "toppar/initial_positions/trans_vector_49",
"trans_vector_50": data_path / "toppar/initial_positions/trans_vector_50"
"trans_vector_0": (data_path /
Copy link
Member

Choose a reason for hiding this comment

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

agreed. it actually reads better with single lines despite going over 80 chars which I like so much. Nonetheless what about:

  1. use Path and not /.
  2. Don't overload operators 😉
TRANSLATION_VECTORS = {
    f"trans_vector_{i}": Path(data_path, 'toppar', 'initial_positions', f'trans_vector_{i}')
    for i in range(51)
    }

@@ -27,34 +27,43 @@ def run(self, module_information):
self.patch_defaults(module_information)

# Get the models generated in previous step
models_to_score = [p for p in self.previous_io.output if p.file_type == Format.PDB]
Copy link
Member

Choose a reason for hiding this comment

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

I agree. please keep the list comprehension.


# Check if multiple models are provided
if len(models_to_score) > 1:
self.finish_with_error("Only one model allowed in LightDock sampling module")
self.finish_with_error("Only one model allowed in LightDock"
Copy link
Member

Choose a reason for hiding this comment

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

in these cases if you really don't wanna go over 80 I advise writing:

_msg = "blablabla"
self.finish_with_error(_msg)

or

self.finish_with_error(
    "blablablabla 1"
    "blablabbla 2"
    )


model = models_to_score[0]
# Check if chain IDs are present
segids, chains = PDBFactory.identify_chainseg(Path(model.path) / model.file_name)
segids, chains = PDBFactory.identify_chainseg(Path(model.path) /
Copy link
Member

Choose a reason for hiding this comment

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

humble suggestion since you are refactoring enforcing 80 chars

_path = Path(model.path, model.file_name)
PDBFactory.indentify_chainseg(_path)

same everywhere. in my opinion. mixing operator overload with line breaks is difficult to read

@@ -51,11 +56,21 @@ def run(self, module_information):
jobs = []

# Get the models generated in previous step
models_to_score = [p for p in self.previous_io.output if p.file_type == Format.PDB]
models_to_score = []
Copy link
Member

Choose a reason for hiding this comment

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

same as before.
if you want to be purist, these logic should be some kind of method of function. but for now just keep the list comprehension

@joaomcteixeira joaomcteixeira changed the title Boring refactor Drop class name analogies favoring technical names Jul 13, 2021
raise HaddockError from re


class Step:
Copy link
Member

Choose a reason for hiding this comment

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

Needs documentation

@joaomcteixeira
Copy link
Member

However, despite we change the class names to more technical ones we should keep the nice HADDOCK-related interface for the users. Phrases of sailors are nice ⛵

@rvhonorato rvhonorato merged commit 8b8b8eb into haddocking:beta1 Jul 13, 2021
@rvhonorato rvhonorato deleted the boring branch July 13, 2021 18:26
This was referenced Jul 16, 2021
joaomcteixeira added a commit to joaomcteixeira/haddock3 that referenced this pull request Jul 16, 2021
Some names `flavour` remained after haddocking#21. This broke any runs where flavour
was not the "default", for example in lightdock.
joaomcteixeira added a commit that referenced this pull request Jul 19, 2021
Update installation instructions after #21
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.

None yet

3 participants