Skip to content

Bugfix/rdf bugfix#114

Open
stkroe wants to merge 47 commits intodevfrom
bugfix/rdf_bugfix
Open

Bugfix/rdf bugfix#114
stkroe wants to merge 47 commits intodevfrom
bugfix/rdf_bugfix

Conversation

@stkroe
Copy link
Collaborator

@stkroe stkroe commented Dec 11, 2024

Bug in rdf
If not all optional keys are defined in the input file, a PQKeyError occurs. But not all optional keys can be set simultaneously.

Suggestion to solve it:

  • This was solved by include all not defined optional keys in the dictionary and set them at None in RDFInputFileReader before the keys are actually used.

  • Further, for the parsing also NoneType in _parse.py the conditions for the InputFileError messages are changed so that None is not throwing an error anymore.

  • The rdf program works only if a topology is given either with restart_file or (moldescriptor_file and restart_file).
    If it is not given, an error occurs during the selection part of the target and reference molecules
    Therefore, in RDFInputFileReader an error message was included.

  • The target_density in RDF was calculated:

target_density = len(self.target_index_combinations[0])

but this is only defined if no_intra_molecular=True. So this was changed to:

        if self.no_intra_molecular:
            target_density = len(self.target_index_combinations[0])
        else:
            target_density = len(self.target_indices)

At the moment, no unexpected errors occur.

@stkroe stkroe added the bug Something isn't working label Dec 11, 2024
@stkroe stkroe requested review from 97gamjak and galjos December 11, 2024 17:45
@97gamjak
Copy link
Collaborator

97gamjak commented Dec 11, 2024

I really like the idea of introducing the "None" if I get it right. Could you provide a sample inputfile? And you execute it then just with rdf <input> or?

@stkroe
Copy link
Collaborator Author

stkroe commented Dec 12, 2024

I really like the idea of introducing the "None" if I get it right. Could you provide a sample inputfile? And you execute it then just with rdf <input> or?

Yes I just use rdf <input> and no further errors have been found so far.

The input file looks like:

reference_selection = H
target_selection = H
delta_r = 0.05
out_file = rdf_test.out
restart_file = md-test.rst
traj_files = test.xyz

self.logger.error(
(
"The restart_file key or the moldescriptor_file key with restart_file key "
"have to be set in order to use the RDF analysis."
Copy link
Collaborator

Choose a reason for hiding this comment

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

If I recall it correctly, this does not have to be the case. For example if you have a plain xyz trajectory and want to give just the plain indices than this should be fine without any restart file or am I wrong?
The restart file should only be necessary if the user want to have a special selection based on atomtypes, molecules, ...

maybe this does not work as expected atm, but then we should tackle the problem there. So that if only an index selection is given the RDF calculation works without restart file.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Okay so i went through your description once again and I see you already mention this issue. Before merging this we should find a solution on how to calculate RDF's without a rst file.

@galjos
Copy link
Collaborator

galjos commented Dec 23, 2024

The tests are blocked most likely due to a numpy function numpy.atleast_1d in Trajectory.__init__(). I have the same issue on mac. Removing it could resolve this one.

@codecov
Copy link

codecov bot commented Jan 7, 2025

Codecov Report

Attention: Patch coverage is 88.57143% with 4 lines in your changes missing coverage. Please review.

Project coverage is 86.84%. Comparing base (d3286b2) to head (0b1efc5).
Report is 22 commits behind head on dev.

Files with missing lines Patch % Lines
PQAnalysis/analysis/rdf/rdf.py 57.14% 3 Missing ⚠️
PQAnalysis/tools/add_molecule.py 66.66% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              dev     #114      +/-   ##
==========================================
+ Coverage   85.43%   86.84%   +1.40%     
==========================================
  Files         125      125              
  Lines        5027     5047      +20     
==========================================
+ Hits         4295     4383      +88     
+ Misses        732      664      -68     
Flag Coverage Δ
unittests 86.84% <88.57%> (+1.40%) ⬆️
Files with missing lines Coverage Δ
PQAnalysis/analysis/rdf/api.py 29.03% <ø> (ø)
PQAnalysis/analysis/rdf/rdf_input_file_reader.py 100.00% <100.00%> (+20.00%) ⬆️
PQAnalysis/analysis/rdf/rdf_output_file_writer.py 94.64% <ø> (+58.92%) ⬆️
PQAnalysis/atomic_system/atomic_system.py 97.66% <100.00%> (+0.04%) ⬆️
...nalysis/io/input_file_reader/pq_analysis/_parse.py 100.00% <100.00%> (ø)
...reader/pq_analysis/pqanalysis_input_file_reader.py 100.00% <100.00%> (+8.88%) ⬆️
PQAnalysis/io/traj_file/trajectory_reader.py 99.42% <ø> (ø)
PQAnalysis/topology/shake_topology.py 98.78% <100.00%> (ø)
PQAnalysis/traj/trajectory.py 99.15% <100.00%> (+0.01%) ⬆️
PQAnalysis/tools/add_molecule.py 89.77% <66.66%> (-0.93%) ⬇️
... and 1 more

... and 3 files with indirect coverage changes

stkroe and others added 8 commits January 7, 2025 16:26
Tests for TestRDFDataWriter and TestRDFLogWriter.

Error in test_write_before_run:
"Reference selection: {rdf.reference_selection}"
has in the output additional curly brackets:
"Reference selection: {{rdf.reference_selection}}"

Suggestion to remove the additional brackets in rdfOutputFileReader
if these brackets are not indendet.

Further change:
additional adding to .gitignore for the .coverage.* on Mac
- Initialization is checked by coveraging also the if conditions
- average_volume() function is  checked
@97gamjak
Copy link
Collaborator

Does it now work also for plain .xyz files?

@stkroe
Copy link
Collaborator Author

stkroe commented Jan 13, 2025

``> Does it now work also for plain .xyz files?

I changed the topology definition in the rdf.py:

if traj.topology is not None: self.topology = traj.topology else: self.topology = self.first_frame.topology

Now it is working without throwing an error and the comparison with restart file topology gives the same rdf results.

@stkroe stkroe requested a review from 97gamjak January 13, 2025 08:39
@github-actions
Copy link
Contributor

PYLINT REPORT

Your code has been rated at 9.79/10 (previous run: 9.79/10, -0.00)

Full report

Raw metrics

type number % previous difference
code 7897 39.93 7910 -13.00
docstring 8677 43.87 8668 +9.00
comment 268 1.35 268 =
empty 2937 14.85 2935 +2.00

Duplication

now previous difference
nb duplicated lines 0 0 0
percent duplicated lines 0.000 0.000 =

Messages by category

type number previous difference
convention 4 2 2
refactor 69 69 69
warning 11 11 11
error 3 3 3

% errors / warnings by module

module error warning refactor convention
PQAnalysis.type_checking 66.67 0.00 0.00 0.00
PQAnalysis 33.33 0.00 0.00 0.00
PQAnalysis.atomic_system.atomic_system 0.00 18.18 13.04 0.00
PQAnalysis.topology.init 0.00 18.18 0.00 0.00
PQAnalysis.tools.traj_to_com_traj 0.00 18.18 0.00 0.00
PQAnalysis.io.moldescriptor_reader 0.00 18.18 0.00 0.00
PQAnalysis.tools.add_molecule 0.00 9.09 8.70 0.00
PQAnalysis.utils.custom_logging 0.00 9.09 0.00 0.00
PQAnalysis.io.write_api 0.00 9.09 0.00 0.00
PQAnalysis.io.nep.nep_writer 0.00 0.00 15.94 25.00
PQAnalysis.io.traj_file.trajectory_reader 0.00 0.00 8.70 0.00
PQAnalysis.analysis.rdf.rdf 0.00 0.00 7.25 0.00
PQAnalysis.utils.files 0.00 0.00 4.35 0.00
PQAnalysis.topology.topology 0.00 0.00 4.35 0.00
PQAnalysis.topology.bonded_topology.dihedral 0.00 0.00 4.35 0.00
PQAnalysis.core.residue 0.00 0.00 4.35 0.00
PQAnalysis.topology.bonded_topology.bonded_topology 0.00 0.00 2.90 0.00
PQAnalysis.topology.bonded_topology.bond 0.00 0.00 2.90 0.00
PQAnalysis.topology.bonded_topology.angle 0.00 0.00 2.90 0.00
PQAnalysis.io.traj_file.frame_reader 0.00 0.00 2.90 0.00
PQAnalysis.core.cell.cell 0.00 0.00 2.90 0.00
PQAnalysis.atomic_system._standard_properties 0.00 0.00 2.90 0.00
PQAnalysis.traj.formats 0.00 0.00 1.45 0.00
PQAnalysis.topology.selection 0.00 0.00 1.45 0.00
PQAnalysis.io.restart_file.restart_reader 0.00 0.00 1.45 0.00
PQAnalysis.io.input_file_reader.pq_analysis._parse 0.00 0.00 1.45 0.00
PQAnalysis.io.input_file_reader.pq.pq_input_file_reader 0.00 0.00 1.45 0.00
PQAnalysis.io.input_file_reader.input_file_parser 0.00 0.00 1.45 0.00
PQAnalysis.io.info_file_reader 0.00 0.00 1.45 0.00
PQAnalysis.io.formats 0.00 0.00 1.45 0.00
PQAnalysis.io.input_file_reader.pq_analysis.pqanalysis_input_file_reader 0.00 0.00 0.00 50.00
PQAnalysis.analysis.rdf.rdf_input_file_reader 0.00 0.00 0.00 25.00

Messages

message id occurrences
too-many-positional-arguments 18
too-many-arguments 18
too-many-instance-attributes 10
inconsistent-return-statements 9
fixme 9
too-many-locals 3
too-complex 3
duplicate-code 3
too-many-branches 2
missing-kwoa 2
unused-import 1
unnecessary-dunder-call 1
too-many-statements 1
too-many-return-statements 1
too-many-public-methods 1
too-many-lines 1
possibly-used-before-assignment 1
missing-final-newline 1
invalid-name 1
arguments-differ 1

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants