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

Update distances.py #1275

Closed
wants to merge 3 commits into from
Closed

Update distances.py #1275

wants to merge 3 commits into from

Conversation

Shtkddud123
Copy link
Contributor

@Shtkddud123 Shtkddud123 commented Mar 30, 2017

Fixes #1262

Changes made in this Pull Request:

  • Added a function distance() which works for a single atomic/molecular distance which works as a compliment of the distance_array() function.

PR Checklist

  • Tests?
  • Docs?
  • CHANGELOG updated?
  • Issue raised/referenced?

@jbarnoud
Copy link
Contributor

Thank you for working on this issue.

Your change broke the test. Among the flow of errors, only that one is relevant:

======================================================================
ERROR: Failure: IndentationError (unexpected indent (distances.py, line 218))
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/home/travis/build/MDAnalysis/mdanalysis/miniconda/envs/pyenv/lib/python2.7/site-packages/nose/loader.py", line 418, in loadTestsFromName
    addr.filename, addr.module)
  File "/home/travis/build/MDAnalysis/mdanalysis/miniconda/envs/pyenv/lib/python2.7/site-packages/nose/importer.py", line 47, in importFromPath
    return self.importFromDir(dir_path, fqname)
  File "/home/travis/build/MDAnalysis/mdanalysis/miniconda/envs/pyenv/lib/python2.7/site-packages/nose/importer.py", line 94, in importFromDir
    mod = load_module(part_fqname, fh, filename, desc)
  File "/home/travis/build/MDAnalysis/mdanalysis/miniconda/envs/pyenv/lib/python2.7/site-packages/MDAnalysisTests/analysis/test_align.py", line 26, in <module>
    import MDAnalysis as mda
  File "/home/travis/build/MDAnalysis/mdanalysis/miniconda/envs/pyenv/lib/python2.7/site-packages/MDAnalysis/__init__.py", line 178, in <module>
    from .lib import log
  File "/home/travis/build/MDAnalysis/mdanalysis/miniconda/envs/pyenv/lib/python2.7/site-packages/MDAnalysis/lib/__init__.py", line 36, in <module>
    from . import distances  # distances relies on mdamath
  File "/home/travis/build/MDAnalysis/mdanalysis/miniconda/envs/pyenv/lib/python2.7/site-packages/MDAnalysis/lib/distances.py", line 218
    name1 = "bynum" + " " + str(atom1) # concatenate string for first selection
    ^
IndentationError: unexpected indent

The tests are run automatically by TravisCI, but you can run them locally to find issues faster. Have a look at our guide to read how.

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.

Thanks for taking on this problem. I added a few quick comments, hopefully they are helpful as you go along.

@@ -206,6 +206,81 @@ def _check_lengths_match(*arrays):
if not all( a.shape == ref for a in arrays):
raise ValueError("Input arrays must all be same shape"
"Got {0}".format([a.shape for a in arrays]))

## NOT COMPLETE - NEED REFINEMENT
def distance(atom1,atom2,box=None):
Copy link
Member

Choose a reason for hiding this comment

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

Please follow PEP8 style, here "leave space after commas".

TODO: refinement of the array structure to take advantage of numpy arrays, and generalize the input var

"""
name1 = "bynum" + " " + str(atom1) # concatenate string for first selection
Copy link
Member

Choose a reason for hiding this comment

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

indentation error

@@ -206,6 +206,81 @@ def _check_lengths_match(*arrays):
if not all( a.shape == ref for a in arrays):
raise ValueError("Input arrays must all be same shape"
"Got {0}".format([a.shape for a in arrays]))

## NOT COMPLETE - NEED REFINEMENT
def distance(atom1,atom2,box=None):
Copy link
Member

Choose a reason for hiding this comment

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

The call signature should be

distance(a, b, box=None)

where a and b are coordinates (numpy arrays of shape (3,)).

No functions in MDAnalysis.lib will make explicit reference to atoms or other "core data structures". Look at distance_array().

name1 = "bynum" + " " + str(atom1) # concatenate string for first selection
name2 = "bynum" + " " + str(atom2) # concatenate string for the second selection

selection1 = u.select_atoms(name1) # select from universe
Copy link
Member

Choose a reason for hiding this comment

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

YOu don't need any selections here. Work with raw coordinates.

if abs(selection1_selection2_array[i][2]) > u.dimensions[5]:
# Z axis minimum image - follows the LAMMPS convention
if selection1_selection2_array[i][2] < 0.0:
selection1_selection2_array[i][2] += u.dimensions[5]
Copy link
Member

Choose a reason for hiding this comment

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

If you're using numpy arrays, use numpy array operations, e.g.

selection1_selection2_array[i, 0:3] += u.dimensions [3:6]

box_type = box_check(box) ## Check type of box and store it in box_type variable

if box_type == 'tri_box':
for i in range(len(selection1_selection2_array)):
Copy link
Member

Choose a reason for hiding this comment

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

This looks all a bit complicated. However, implement your tests and then see if your solution works. Once you have one solution it can be improved. But tests are important early on.


return separation


Copy link
Member

Choose a reason for hiding this comment

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

Implement tests!!!!

@orbeckst
Copy link
Member

@Shtkddud123 , if you want to get in a PR for GSoC then I recommend you're not doing this one (this will take longer!) but something very easy such as #1246 or look at #597 (and just write a test that tests raising of an exception that is not being tested yer – the issue #597 has more details).

@Shtkddud123
Copy link
Contributor Author

Shtkddud123 commented Mar 31, 2017 via email

@orbeckst
Copy link
Member

@Shtkddud123 are you interested in continuing this PR or can I close it for the time being?

@Shtkddud123
Copy link
Contributor Author

Shtkddud123 commented May 15, 2017 via email

@orbeckst
Copy link
Member

orbeckst commented May 16, 2017 via email

@orbeckst
Copy link
Member

Hi @Shtkddud123, thanks for your interest in contributing. There hasn't been much more activity recently and there isn't code in the PR yet that relates to distances and it shows "unknown repository" as the source. Therefore I am going to close this PR. Please submit a new PR if you find the time to work on this problem again. Hope to see you back here!

@orbeckst orbeckst closed this Jul 10, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants