Replace wildcard imports with explicit imports (as discussed on Twitter with @jjgray)
Imports were also made consistent through all notebooks
A few PEP8 compliance changes were made (plus removing semi-colons at the end of some lines)
Direct imports from rosetta.xxx were all replaced by pyrosetta.rosetta.xxx following deprecation warnings.
Changes were spread to code samples in markdown cells, but not to student-notebooks yet.
A few tweaks to what was discussed: rosetta was actually never imported, instead core and protocols from pyrosetta.rosetta are explicitly imported if needed. This makes relatively short lines while being more understandable:
Long import paragraphs full of functions that are used only once:
import stuff
from pyrosetta.rosetta.protocols.minimization_packing import MinMover
from pyrosetta.rosetta.protocols.analysis.simple_metrics import RunSimpleMetricsMover
import more stuff
`from pyrosetta.rosetta import core, protocols` has the advantages of both: the programmer doesn't need to go back to the imports to edit them, and the location is not drowned in many imports statements and is clearly stated in the code, making it easily reused; meanwhile it is (relatively) shorter, hence more easily read and written. This style could already be found in notebook [14.00](https://github.com/RosettaCommons/PyRosetta.notebooks/blob/200a6d5489f2108999563ae38c7e3fcdabe8f5fe/notebooks/14.00-RNA-Basics.ipynb).
Imports also followed these guidelines:
- If several commands from one module were used extensively then the module may be imported explicitly (`from pyrosetta.rosetta.protocols import antibody, docking`).
- If, from a module, only one functionality was used more than two times, then it may be imported explicitly.
A few common imports were also generalized to all notebooks when indicated by the guidelines:
- `import pyrosetta.rosetta.core.select.residue_selector as selections` (found in notebook [06.02](https://github.com/RosettaCommons/PyRosetta.notebooks/blob/200a6d5489f2108999563ae38c7e3fcdabe8f5fe/notebooks/12.01-RosettaAntibody-Framework-and-SimpleMetrics.ipynb) and [12.01](https://github.com/RosettaCommons/PyRosetta.notebooks/blob/200a6d5489f2108999563ae38c7e3fcdabe8f5fe/notebooks/12.01-RosettaAntibody-Framework-and-SimpleMetrics.ipynb))
- `import pyrosetta.rosetta.core.simple_metrics as sm` (found in notebook 12.01 importing `core.simple_metrics.metrics as sm`. This seemed more appropriate and versatile as it shortens both `sm.metrics` and `sm.per_residue_metrics`)
- `from pyrosetta.rosetta.core.pack import task`. Some notebooks stated: `from pyrosetta.rosetta.core.pack.task import TaskFactory, operators`. Instead, only importing `task` permits to clearly label TaskOperations as `task.operation` and TaskFactory is easily called, while making the import statement briefer:
```python
tf = task.TaskFactory()
tf.push_back(task.operation.InitializeFromCommandline())
Imports of pyrosetta.teaching were all removed after chapter 6. The incentives for using it - protecting naive students from complex pyrosetta package structure - had no longer to be satisfied given how heavily chapter 6 relies on this structure. Using teaching instead of actual imports afterward seemed only detrimental, as it made the code harder to reuse in a production environment: a beginner had to either guess where to find the function, or run type(teaching.function). Worst case scenario: it encourages to reuse teaching in professional scripts, which I don't think is the intended use.
Duplicates of these notebooks were all tested manually in an effort to avoid as many metadata or output changes as possible. Issues found were also found in the notebooks prior to changes. Chapter 16 notebooks were the least tested, but given that there imports were just rearranged to be PEP8 compliant there shouldn't be any problem (hopefully).
Off-topic comment (sorry): I am currently unemployed and looking for a PhD or job related to protein design. I would be more than glad to help writing jupyter notebooks, develop python package, use PyRosetta, do wet lab or all these at once. These changes were not done to advertise myself, but I guess I should try my luck.
Replace wildcard imports with explicit imports (as discussed on Twitter with @jjgray)
rosetta.xxx
were all replaced bypyrosetta.rosetta.xxx
following deprecation warnings.A few tweaks to what was discussed:
rosetta
was actually never imported, insteadcore
andprotocols
frompyrosetta.rosetta
are explicitly imported if needed. This makes relatively short lines while being more understandable:This permits to avoid two pitfalls:
a_lot_of_code()
minmover = MinMover() design_metrics = RunSimpleMetricsMover()
pyrosetta.teaching
were all removed after chapter 6. The incentives for using it - protecting naive students from complex pyrosetta package structure - had no longer to be satisfied given how heavily chapter 6 relies on this structure. Usingteaching
instead of actual imports afterward seemed only detrimental, as it made the code harder to reuse in a production environment: a beginner had to either guess where to find the function, or runtype(teaching.function)
. Worst case scenario: it encourages to reuseteaching
in professional scripts, which I don't think is the intended use.Duplicates of these notebooks were all tested manually in an effort to avoid as many metadata or output changes as possible. Issues found were also found in the notebooks prior to changes. Chapter 16 notebooks were the least tested, but given that there imports were just rearranged to be PEP8 compliant there shouldn't be any problem (hopefully).
Off-topic comment (sorry): I am currently unemployed and looking for a PhD or job related to protein design. I would be more than glad to help writing jupyter notebooks, develop python package, use PyRosetta, do wet lab or all these at once. These changes were not done to advertise myself, but I guess I should try my luck.