Python Programming for Biology: Bioinformatics and Beyond



Download 7,75 Mb.
Pdf ko'rish
bet227/514
Sana30.12.2021
Hajmi7,75 Mb.
#91066
1   ...   223   224   225   226   227   228   229   230   ...   514
Bog'liq
[Tim J. Stevens, Wayne Boucher] Python Programming

Centring coordinates

Firstly  in  this  section  we  will  need  to  import  some  mathematical  functions  from  the

numpy module to allow us to efficiently work with arrays of numbers. Note especially that

the sqrt and exp functions have the same names as the equivalents in the math module, but

work on both NumPy arrays and single numbers.

from numpy import zeros, ones, cross, sqrt, linalg, exp, identity




Before  we  align  structural  coordinates  by  optimising  rotations,  we  first  need  to  move

the input structures so that their centres are aligned. Effectively this means calculating the

centre of mass of each structure and moving its coordinates so that it is repositioned with

the centre at the zero points of all the axes (x, y and z). The centre needs to be the zero

point  because  the  rotational  transformations  we  will  consider  are  all  rotations  about  this

centre.  The  function  that  moves  an  array  of  coordinates  naturally  takes  the  array  as  an

input  argument,  together  with  an  array  of  weights.  Note  that  both  arguments  must  be

NumPy array objects, which allows us to perform operations on whole arrays of numbers

at  once,  rather  than  using  loops;  this  is  quicker  to  run  and  arguably  easier  to  read  (once

you understand NumPy).

The weights array allows different kinds of atom to have different degrees of influence,

typically derived from the atom’s mass. Inside the function we first multiply the elements

of  the  coordinates  array  by  the  weights  array,  taking  special  notice  that  we  use  the

transpose  of  coords  array  where  rows  are  switched  with  columns.  This  transposition  is

required because element-by-element multiplication of a one-dimensional array (weights)

with a two-dimensional array (coords) works on a per-row basis. If we switch rows with

columns then we get three rows that correspond to all of the x, y and z values respectively,

and what we require is to multiply all of these rows separately with the weights. Given the

weighted coordinates (wCoords) we then find the summation of the x, y, and z coordinates

independently,  i.e.  we  add  up  along  the  rows  (specified  with  sum(axis=1)),  the  result  of

which is an array of three numbers. This array of totals is then divided by the total weight

to  get  an  average  that  represents  the  centre  of  the  coordinates  (center).  Finally,  all  the

coordinates are moved to the new centre (0, 0, 0) by taking away the old centre position;

another  example  of  a  per-row  numpy.array  operation.  The  new  coordinates  and  the  old

centre  position  (which  represents  a  translation  operation)  are  passed  back  from  the

function.

def centerCoords(coords, weights):

wCoords = coords.transpose() * weights

xyzTotals = wCoords.sum(axis=1)

center = xyzTotals/sum(weights)

coords -= center

return coords, center




Download 7,75 Mb.

Do'stlaringiz bilan baham:
1   ...   223   224   225   226   227   228   229   230   ...   514




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish