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

Work around more DX parsing issues by other apps #58

Merged
merged 7 commits into from
Apr 8, 2019

Conversation

giacomofiorin
Copy link
Contributor

@giacomofiorin giacomofiorin commented Nov 12, 2018

The code below from the GridForcesGrid.C file in NAMD:

fscanf(poten_fp, "object %*d class array type double rank 0 "
                 "items %*d data follows\n");

will only work if the quote character (introduced in 115b05a to work around a similar problem in the PyMol parser - see #35) is omitted. This is done via the optional typequote keyword, to accompany type.

The other commit has to do with another inconsistency in PyMol. Its DX parser fails to parse tiny numbers (i.e. with an exponent lower than -100) despite using a float for parsing and the %f format in the function:

static int ObjectMapACNTStrToMap(ObjectMap * I, char *ACNTStr, int bytes, int state,
                                 int quiet);

The most recent versions of PyMol now support type float:
schrodinger/pymol-open-source@4bbe425
which is a reasonable decision, given that it is actually not parsing doubles correctly :-)

This change works around another example of poorly hard-coded DX parser
(see also issue MDAnalysis#35).

See the code below from the GridForcesGrid.C file in NAMD:
fscanf(poten_fp, "object %*d class array type double rank 0 "
                 "items %*d data follows\n");
which will only work if the quote character (introduced in 115b05a to appease
the PyMol parser) is omitted.
Again, this is a workaround for an issue in the PyMol DX parser that fails to
parse tiny numbers (i.e. with an exponent lower than -100).  If it seems
inconsistent with requiring "type double", it is because the DX parser uses a
"float" to read the data:

static int read_dx_data(void *v, int set, float *datablock,
                         float *colorblock) {
  ...
  float grid;
  ...

Observed with PyMol up to 2.3.0.
@giacomofiorin
Copy link
Contributor Author

The amended commit now handles also test cases where grids of integer values are being used.

Note that the AppVeyor test fails due to Visual Studio configuration issues (probably unrelated to this PR).

@giacomofiorin
Copy link
Contributor Author

Hello, a brief reminder that the Travis test passes, whereas the AppVeyor test fails due to causes unrelated to this PR:

The build phase is set to "MSBuild" mode (default), but no Visual Studio project or solution files were found in the root directory. If you are not building Visual Studio project switch build mode to "Script" and provide your custom build command.

@orbeckst
Copy link
Member

orbeckst commented Apr 5, 2019

@giacomofiorin sorry for the long silence – I haven't had a look at GridDataFormats in a while. In general, ping me with @orbeckst .

I'll have a look at your contribution, thank you!

Copy link
Member

@orbeckst orbeckst left a comment

Choose a reason for hiding this comment

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

Minor comments and please

  • add yourself to AUTHORS
  • add an entry to CHANGELOG (under 0.5.0)

(I will do a quick release of 0.4.1 and a 0.5.0 section will appear soon, you just have to merge master into your branch.)

If you can think of a test that explicitly tests your functionality then add one, please.

gridData/core.py Outdated Show resolved Hide resolved
@orbeckst orbeckst self-assigned this Apr 5, 2019
@codecov
Copy link

codecov bot commented Apr 6, 2019

Codecov Report

Merging #58 into master will increase coverage by 0.1%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master      #58     +/-   ##
=========================================
+ Coverage   86.42%   86.53%   +0.1%     
=========================================
  Files           5        5             
  Lines         759      765      +6     
  Branches      109      110      +1     
=========================================
+ Hits          656      662      +6     
  Misses         61       61             
  Partials       42       42
Impacted Files Coverage Δ
gridData/OpenDX.py 82.22% <100%> (+0.3%) ⬆️
gridData/core.py 92.85% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 8f40542...63441c0. Read the comment docs.

@giacomofiorin
Copy link
Contributor Author

@orbeckst Thanks. Both new features are used within test_dx.py, so that should be sufficient.

@orbeckst
Copy link
Member

orbeckst commented Apr 6, 2019

Ok, then add yourself to AUTHORS and add an entry to CHANGELOG. I don't have an updated CHANGELOG yet so use the current one and just add your entry under 0.4.1 but I will put whatever you write in the correct spot before I merge.

@giacomofiorin
Copy link
Contributor Author

I did that in the merge commit, except I put 0.5.0 as suggested. Feel free to edit the description as needed.

gridData/core.py Outdated
file_format : {'dx', 'pickle', None} (optional)
output file format, the default is "dx"

type : str (optional)
for DX, set the output DX array type, e.g., "double" or
"float"; note that PyMOL only understands "double" (see
Copy link
Member

Choose a reason for hiding this comment

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

In the light of your comment

The most recent versions of PyMol now support type float: schrodinger/pymol-open-source@4bbe425
which is a reasonable decision, given that it is actually not parsing doubles correctly :-)

is this comment in the docs still relevant?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It may still be relevant if the numbers in the DX map are outside the allowable range for a 32-bit float, regardless of which type is stated in the DX header. You may want to actually discourage using type=double because Pymol doesn't really support it.

However, this is really a Pymol issue, and in all practical scenarios it is avoided now with the new format. So I've just removed the comment for simplicity.

Copy link
Member

@orbeckst orbeckst left a comment

Choose a reason for hiding this comment

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

Please change one reST line. Thanks!

gridData/core.py Outdated Show resolved Hide resolved
@orbeckst orbeckst merged commit 3693a90 into MDAnalysis:master Apr 8, 2019
@orbeckst
Copy link
Member

orbeckst commented Apr 8, 2019

@giacomofiorin thank you for your contribution. Sorry it took such a long time. Next time ping me with '@orbeckst' to get my attention.

orbeckst added a commit that referenced this pull request Apr 8, 2019
- fixed doc building failure (only encountered locally and on RTD, not in tests)
- included @giacomofiorin in the author list displayed in the docs (was forgotten
  in PR #58)
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.

2 participants