[Tutor] Euclidean Distances between Atoms in a Molecule.
Asurin
qiaozha at gmail.com
Sun Apr 2 19:06:47 EDT 2017
Dr. Molnar:
This might be your solution:
>>> import numpy
>>> a = numpy.array((-3.265636, 0.198894, 0.090858))
>>> b = numpy.array((-1.307161, 1.522212, 1.003463))
>>> dist = numpy.linalg.norm(a-b)
>>> dist
2.5337013913983633
>>>
Qiao Qiao
> On Apr 2, 2017, at 1:41 PM, Stephen P. Molnar <s.molnar at sbcglobal.net> wrote:
>
> I am trying to port a program that I wrote in FORTRAN twenty years ago into Python 3 and am having a hard time trying to calculate the Euclidean distance between each atom in the molecule and every other atom in the molecule.
>
> Here is a typical table of coordinates:
>
>
> MASS X Y Z
> 0 12.011 -3.265636 0.198894 0.090858
> 1 12.011 -1.307161 1.522212 1.003463
> 2 12.011 1.213336 0.948208 -0.033373
> 3 14.007 3.238650 1.041523 1.301322
> 4 12.011 -5.954489 0.650878 0.803379
> 5 12.011 5.654476 0.480066 0.013757
> 6 12.011 6.372043 2.731713 -1.662411
> 7 12.011 7.655753 0.168393 2.096802
> 8 12.011 5.563051 -1.990203 -1.511875
> 9 1.008 -2.939469 -1.327967 -1.247635
> 10 1.008 -1.460475 2.993912 2.415410
> 11 1.008 1.218042 0.451815 -2.057439
> 12 1.008 -6.255901 2.575035 1.496984
> 13 1.008 -6.560562 -0.695722 2.248982
> 14 1.008 -7.152500 0.390758 -0.864115
> 15 1.008 4.959548 3.061356 -3.139100
> 16 1.008 8.197613 2.429073 -2.588339
> 17 1.008 6.503322 4.471092 -0.543939
> 18 1.008 7.845274 1.892126 3.227577
> 19 1.008 9.512371 -0.273198 1.291080
> 20 1.008 7.147039 -1.365346 3.393778
> 21 1.008 4.191488 -1.928466 -3.057804
> 22 1.008 5.061650 -3.595015 -0.302810
> 23 1.008 7.402586 -2.392148 -2.374554
>
> What I need for further calculation is a matrix of the Euclidean distances between the atoms.
>
> So far in searching the Python literature I have only managed to confuse myself and would greatly appreciate any pointers towards a solution.
>
> Thanks in advance.
>
> --
> Stephen P. Molnar, Ph.D. Life is a fuzzy set
> www.molecular-modeling.net Stochastic and multivariate
> (614)312-7528 (c)
> Skype: smolnar1
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list