samirelanduk / atomium

Python macromolecular parsing (with .pdb/.cif/.mmtf parsing and production)
https://atomium.bio
MIT License
103 stars 19 forks source link

implemented angle_with method #2

Closed gf712 closed 7 years ago

gf712 commented 7 years ago

Hi, I saw that you needed to implement some code to calculate the angle between two bonds. I added the method angle_with() in the Bond class. angle_with takes two parameters: another Bond object (bond_obj) and in_degrees, which expects a boolean and returns the angle of two bonds in degrees if set toTrue.

So for the angle between the OH bonds of water you would do the following:

>>> from atomium.structures.atoms import Bond, Atom

# create bonds of water molecule
>>> bond1 = Bond(Atom('O',0,0,0), Atom('H', 0.757,  0.586, 0.0))
>>> bond2 = Bond(Atom('O',0,0,0), Atom('H', -0.757, 0.586, 0.0))

# calculate angle
>>> bond1.angle_with(bond2)
104.51249572721815

I also created a private method in Bond to calculate the vector and a function to calculate the dot product.

I hope this helps!

samirelanduk commented 7 years ago

Hi Gil,

Thanks a lot for taking the time to do this! This is actually the first time anyone has made a pull request on one of my projects so I'm a little unsure of the process, but I appreciate the contribution.

I do need an angle_with method, but currently I use my other library geometrica to handle geometry stuff (the rotate() method of AtomicStructure is an example). However as I'm not likely to get around to that this release, this would be an excellent implementation for this and probably the next release.

I'm currently working in the 0.3 branch and when I'm finished that release (hopefully next week) I will try and merge your branch into that one (if you can merge pull requests into non-master branches - still new to me!).

Thanks again (and see you soon probably!), Sam