Re: getting the center of mass of each part of a molecule

2017-05-22 Thread jladasky
On Saturday, May 20, 2017 at 9:13:39 AM UTC-7, qasi...@gmail.com wrote
> I have more than 100 ligand molecules. The image I showed at the beginning of 
> this discussion was only an example. It had missing atoms. 
> See it without missing any atom in the pdb format (coordinates in Angstrom 
> unit):

[snip atomic coordinate tables]

> I am doing molecular dynamics simulation of protein-ligand complex. The issue 
> is to keep the ligand in the binding site of the protein during simulation 
> when turned off the interactions (van der waals, coulomb...) between the 
> ligand and protein. In that case, to keep the ligand in the bindind site I 
> need to apply the translational and rotational restraints (distance, angle, 
> dihedral restraints). The more detail is here 
> http://pubs.acs.org/doi/abs/10.1021/jp0217839

Well now, that's Ph.D level work.  I work with GROMACS myself.  

I tried to obtain a copy of the paper.  Why is a 14 year old article behind a 
paywall?  I requested a reprint from the authors through ResearchGate.
 
> My aim is to get the COM of the whole ligand (I already do it) and divide the 
> ligand in two parts and find to the COM of each part. Then I will apply the 
> distance, angle and dihedral restraints on the atoms of the ligand and 
> protein.  
> -The first distance restraints will be between one of the ligand heavy atom 
> closest to the ligand COM (COM for whole ligand atoms) and one of the protein 
> atoms closest to the ligand COM. 
> -The second distance restraints  will be between one of the ligand heavy atom 
> closest to the COM of the first part of ligand in two parts and one of the 
> protein atoms closest to the COM of the first part of ligand in two parts. 
> -And the third distance restraints  will be between one of the ligand heavy 
> atom closest to the COM of the second part of ligand in two parts and one of 
> the protein atoms closest to the COM of the second part of ligand in two 
> parts.
> 
> That is, I will form 3 bonds between ligand and protein. Hope that makes 
> clear what I am trying to do.

Is that the method that was used in the research paper, or is that something 
that you devised on your own?
 
> Please tell me on the python code what I need to do.

Your requirements are still rather more vague than you realize.  I think that 
you are counting on the fact that the atomic coordinates in a PDB file include 
a certain amount of noise, and possibly also any strain in the ligand molecule. 
 If you have a truly symmetrical ligand, your center of mass computations will 
not be robust.

But I see the general idea behind what you are trying to do.  And I suppose any 
method that forms three virtual bonds between three distinct atoms in ligand 
and the protein will do the job.  Maybe you don't care that you get the true 
center of mass, just that you get close to it.

How much Python do you want to learn?  I am going to suggest a basic 
modification to your approach to coding.  You will have several steps in this 
algorithm.  Learn to structure your code in in a way which allows you to read 
your algorithm in plain language using comments, descriptive variable names, or 
descriptive function names.  

Right now you show one function called heavy_atoms.  That is not a very 
descriptive name.  I'm not even sure why it's a function at all, because it 
doesn't return any values to whatever called it.  If your program is short and 
you only want to work with global variables, you can skip the use of functions.

I would like to see your whole program.  However, at this stage it's probably 
not of interest to other readers of the newsgroup.  Please consider continuing 
through email.  Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: getting the center of mass of each part of a molecule

2017-05-20 Thread qasimpars
I have more than 100 ligand molecules. The image I showed at the beginning of 
this discussion was only an example. It had missing atoms. 
See it without missing any atom in the pdb format (coordinates in Angstrom 
unit):
ATOM  1  O1  LIG 1  46.050  50.290  26.860
ATOM  2  O2  LIG 1  46.070  47.530  27.170  
ATOM  3  C1  LIG 1  47.630  49.260  23.730
ATOM  4  C2  LIG 1  48.200  49.870  22.500
ATOM  5  C3  LIG 1  47.090  50.070  24.730   
ATOM  6  C4  LIG 1  46.570  49.490  25.890   
ATOM  7  C5  LIG 1  47.650  47.870  23.890
ATOM  8  C6  LIG 1  46.590  48.100  26.040 
ATOM  9  C7  LIG 1  47.120  47.290  25.050
ATOM 10  C8  LIG 1  47.160  50.610  21.680
ATOM 11  C9  LIG 1  46.450  51.660  26.860
ATOM 12  C10 LIG 1  46.910  51.920  21.790
ATOM 13  H1  LIG 1  48.640  49.150  21.820 
ATOM 14  H2  LIG 1  48.980  50.600  22.700   
ATOM 15  H3  LIG 1  47.080  51.150  24.610
ATOM 16  H4  LIG 1  48.070  47.240  23.110
ATOM 17  H5  LIG 1  47.140  46.210  25.170
ATOM 18  H6  LIG 1  46.580  50.030  20.960
ATOM 19  H7  LIG 1  45.570  52.300  26.810
ATOM 20  H8  LIG 1  47.090  51.850  26.000
ATOM 21  H9  LIG 1  47.000  51.860  27.780
ATOM 22  H10 LIG 1  46.190  48.140  27.920
ATOM 23  H11 LIG 1  46.220  52.400  21.250
ATOM 24  H12 LIG 1  46.750  52.530  22.680 

The same ligand coordinate file in gro format (coordinates in nanometer unit) 
is here as well: 
1LIG O11   4.605   5.029   2.686
1LIG O22   4.607   4.753   2.717
1LIG C13   4.763   4.926   2.373
1LIG C24   4.820   4.987   2.250
1LIG C35   4.709   5.007   2.473
1LIG C46   4.657   4.949   2.589
1LIG C57   4.765   4.787   2.389
1LIG C68   4.659   4.810   2.604
1LIG C79   4.712   4.729   2.505
1LIG C8   10   4.716   5.061   2.168
1LIG C9   11   4.645   5.166   2.686
1LIGC10   12   4.691   5.192   2.179
1LIG H1   13   4.864   4.915   2.182
1LIG H2   14   4.898   5.060   2.270
1LIG H3   15   4.708   5.115   2.461
1LIG H4   16   4.807   4.724   2.311
1LIG H5   17   4.714   4.621   2.517
1LIG H6   18   4.658   5.003   2.096
1LIG H7   19   4.557   5.230   2.681
1LIG H8   20   4.709   5.185   2.600
1LIG H9   21   4.700   5.186   2.778
1LIGH10   22   4.619   4.814   2.792
1LIGH11   23   4.622   5.240   2.125
1LIGH12   24   4.675   5.253   2.268
I am doing molecular dynamics simulation of protein-ligand complex. The issue 
is to keep the ligand in the binding site of the protein during simulation when 
turned off the interactions (van der waals, coulomb...) between the ligand and 
protein. In that case, to keep the ligand in the bindind site I need to apply 
the translational and rotational restraints (distance, angle, dihedral 
restraints). The more detail is here 
http://pubs.acs.org/doi/abs/10.1021/jp0217839

My aim is to get the COM of the whole ligand (I already do it) and divide the 
ligand in two parts and find to the COM of each part. Then I will apply the 
distance, angle and dihedral restraints on the atoms of the ligand and protein. 
 
-The first distance restraints will be between one of the ligand heavy atom 
closest to the ligand COM (COM for whole ligand atoms) and one of the protein 
atoms closest to the ligand COM. 
-The second distance restraints  will be between one of the ligand heavy atom 
closest to the COM of the first part of ligand in two parts and one of the 
protein atoms closest to the COM of the first part of ligand in two parts. 
-And the third distance restraints  will be between one of the ligand heavy 
atom closest to the COM of the second part of ligand in two parts and one of 
the protein atoms closest to the COM of the second part of ligand in two parts.

That is, I will form 3 bonds between ligand and protein. Hope that makes clear 
what I am trying to do.

Please tell me on the python code what I need to do.

Thanks.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: getting the center of mass of each part of a molecule

2017-05-19 Thread jladasky
On Friday, May 19, 2017 at 4:17:23 PM UTC-7, qasi...@gmail.com wrote:
> The center of mass of the whole ligand that I calculated is the center of 
> geometry (the average/mean atomic positions) from the sample input file 
> provided. I don't take other things into account, such as knowledge of the 
> mass of each atom and so on. The difference between the center of mass and 
> the center of geometry/atom positions is probably small, and my aim is only 
> to select the atom closest to the center of geometry.

Just a quick note, the image that you showed at the beginning of this 
discussion would not have picked C1 as the closest atom to the center of the 
molecule.  If your molecule consisted of only the benzene ring C1...C6, the 
center of mass would be exactly at the center.  Adding C7 would shift the 
center directly toward C2.  C8 and C9, as you have drawn them, shift the center 
further, in a direction pointing somewhere between C2 and C4.

> Dear Gregory Ewing, lets consider I get the center of geometry (the average 
> positions of atoms - X, Y, Z) of the whole molecule. Then I can compare those 
> average positions X, Y and Z and find the greatest one, and list separately 
> the ligand atoms according to the greatest average position out of X, Y and Z 
> (The greatest one is the "longest" axis of the molecule in some sense). This 
> way, the ligand atoms will have been divided in two parts, right? After that, 
> I can calculate the center of geometry of each part. Does this procedure make 
> sense? If no, what do you suggest me to divide the ligand/molecule in two 
> parts?

Any procedure that serves your intended purpose is the one that makes sense.  
Personally, I don't understand the goal of dividing a molecule into two parts 
and then computing separate centers of mass for each, but maybe you can explain 
why this is a useful thing to do.

As you have described it, here is one possible way to proceed?

1) Identify "the" atom which is closest to the center of mass.  As I mentioned, 
there could be more than one atom which is the same distance from the center.  
You need to define what to do in that case.
2) Rank the atoms in order of Euclidean distance from the center; choose "the 
one" that is farthest from the center.  Again, there could be ties.  What do 
you do?
4) Define a vector from the center to the most distant atom.
5) The plane that divides the molecule in half is defined as passing through 
"the" central atom, and is normal to the vector.

I'm not sure that's what you want.  Using this algorithm, the picture that you 
show would not divide the molecule in the way you describe.  I predict that C2 
would be closest to the center of mass, so C2 would be the excluded atom.  C9 
would be the most distant from the center of mass.  C1, C3, C5 and C6 would be 
on one side of the dividing plane.  C7, C8, and C9 would be on the other.  I'm 
not quite sure which side C4 would be on.

In your data table, you did not give coordinates for all 9 atoms.  With that 
information we could check whether your coordinates agree with your picture.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: getting the center of mass of each part of a molecule

2017-05-19 Thread qasimpars
The center of mass of the whole ligand that I calculated is the center of 
geometry (the average/mean atomic positions) from the sample input file 
provided. I don't take other things into account, such as knowledge of the mass 
of each atom and so on. The difference between the center of mass and the 
center of geometry/atom positions is probably small, and my aim is only to 
select the atom closest to the center of geometry.

Dear Gregory Ewing, lets consider I get the center of geometry (the average 
positions of atoms - X, Y, Z) of the whole molecule. Then I can compare those 
average positions X, Y and Z and find the greatest one, and list separately the 
ligand atoms according to the greatest average position out of X, Y and Z (The 
greatest one is the "longest" axis of the molecule in some sense). This way, 
the ligand atoms will have been divided in two parts, right? After that, I can 
calculate the center of geometry of each part. Does this procedure make sense? 
If no, what do you suggest me to divide the ligand/molecule in two parts?




-- 
https://mail.python.org/mailman/listinfo/python-list


Re: getting the center of mass of each part of a molecule

2017-05-19 Thread Gregory Ewing

qasimp...@gmail.com wrote:

"The atoms of the first part/half according to the main COM of
the ligand are C2, C7, C8 and C9. As for the second part they are C3, C4, C5
and C6 atoms."


Think *very* carefully about how you made that decision. Was it
based *only* on the position of the centre of mass, or did you
take other things into account, such as knowledge of which
atoms are bonded to which other atoms?

In other words, if someone just gave you a list of the positions
of the atoms and nothing else, would you be able to figure out
which atoms belonged to which half, without seeing a picture of
the molecule? If so, how would you do it?

If you need information about the bonds, then there's no way
a program could do it from the sample input file you provided,
because it only contains positions.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: getting the center of mass of each part of a molecule

2017-05-18 Thread jladasky
On Thursday, May 18, 2017 at 2:44:54 PM UTC-7, qasi...@gmail.com wrote:
> Yes, I wrote: "The atoms of the first part/half according to the main COM of 
> the ligand are C2, C7, C8 and C9. As for the second part they are C3, C4, C5 
> and C6 atoms." It was just an example. In fact, I don't know which atoms 
> belong to each half. The code should do it of course.
> 
> That is, I gave it as an example. I thought someone can understand what the 
> two parts of molecule are and what I am trying to do if I give such an 
> example.

We are going in circles.

Do you want your code to AUTOMATICALLY make the decision that atoms 2, 7, 8, 
and 9 comprise one "half" of your molecule, and atoms 3, 4, 5, and 6 comprise 
the other "half"?  Then you need criteria, that you can turn into code.  

You said you wanted to exclude "the" atom which is nearest to the center of 
mass from either subset.  (What if there's a tie?  As in fact there could be, 
if you allowed for all the possible rotamers in the C2-C7 and C7-C8 bonds?)  
You also stated that you wanted the code "to find which atoms belong to each 
half."  You still don't say HOW you choose halves.  ONE example is obviously 
not enough to determine a general pattern.  There is no "right" answer to the 
question, "which half of the molecule is this?"  A human can't figure it out.  
A computer can't figure it out.  If you don't know what you mean, we can't help 
you.

(This link is relevant: http://dilbert.com/strip/2006-01-29)

Where are you getting this problem?  Do you have a reference of any kind?  I am 
actually interested in your problem, because I do computational chemistry as 
well as program in Python.

Alternately: could a user manually enter the subset information into the 
computer at a prompt?  Then, you don't need code to do anything except select 
the subsets that the user wants.  That's considerably easier.

Maybe you should start there.  Write code which lets the user name the atoms in 
the two subsets (possibly after automatically excluding "the central atom").  
Make the code modular, so that you can go back later and add a function to 
automatically create the two subsets -- once you know what you actually want.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: getting the center of mass of each part of a molecule

2017-05-18 Thread qasimpars
Yes, I wrote: "The atoms of the first part/half according to the main COM of 
the ligand are C2, C7, C8 and C9. As for the second part they are C3, C4, C5 
and C6 atoms." It was just an example. In fact, I don't know which atoms belong 
to each half. The code should do it of course.

That is, I gave it as an example. I thought someone can understand what the two 
parts of molecule are and what I am trying to do if I give such an example.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: getting the center of mass of each part of a molecule

2017-05-18 Thread jladasky
On Thursday, May 18, 2017 at 1:43:20 PM UTC-7, qasi...@gmail.com wrote:
> Dear Gregory Ewing,
> 
> As I said before, I need to divide the molecule into two parts but don't know 
> how to do it? It seems that I need to choose/determine a plane in 3D space 
> which cuts the molecule in two parts. As John Ladasky suggested, I need to 
> describe the criteria that cut needs to satisfy as well. Could you please 
> tell me on the code how to do those steps?

You define the criteria, and then you write the code.

In your original post, you wrote: "The atoms of the first part/half according 
to the main COM of the ligand are C2, C7, C8 and C9. As for the second part 
they are C3, C4, C5 and C6 atoms."

HOW did YOU make that decision?  That's what you need to specify in order to 
write code.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: getting the center of mass of each part of a molecule

2017-05-18 Thread qasimpars
Dear Gregory Ewing,

As I said before, I need to divide the molecule into two parts but don't know 
how to do it? It seems that I need to choose/determine a plane in 3D space 
which cuts the molecule in two parts. As John Ladasky suggested, I need to 
describe the criteria that cut needs to satisfy as well. Could you please tell 
me on the code how to do those steps?

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: getting the center of mass of each part of a molecule

2017-05-18 Thread John Ladasky
On Thursday, May 18, 2017 at 3:55:01 AM UTC-7, qasi...@gmail.com wrote:
> @jladasky and @Gregory:
> 

> 3) Divide the ligand molecule into two parts (except for ligand heavy atom 
> closest to the COM of the whole ligand) based on the COM previously 
> calculated.

OK, now I agree with Gregory Ewing.  This part of your problem is incompletely 
defined.  Divide the molecule into two parts... how?  You need to choose a 
plane in 3-dimensional space which cuts your molecule in two.  Describe the 
criteria that this cut needs to satisfy.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: getting the center of mass of each part of a molecule

2017-05-18 Thread qasimpars
@jladasky and @Gregory:

Thanks your replies. 
The code should do the steps below:

1) Calculate the center of mass (COM) of the whole ligand molecule with the 
atomic coordinates (x,y,z)
2) Find the ligand heavy atom closest to the COM of the whole ligand molecule
3) Divide the ligand molecule into two parts (except for ligand heavy atom 
closest to the COM of the whole ligand) based on the COM previously calculated.
4) Calculate the COM of each part divided.

I do the first two steps and get correct result. The difficult task/step I 
couldn't overcome is to divide the ligand molecule into two parts (except for 
ligand heavy atom closest to the COM of the whole ligand) based on the COM 
previously calculated and to find which atoms belong to each half.

Any help will be appreciated. 






-- 
https://mail.python.org/mailman/listinfo/python-list


Re: getting the center of mass of each part of a molecule

2017-05-18 Thread Gregory Ewing

jlada...@itu.edu wrote:

I took the OP at their word.  S/he wants the center of mass of the whole
molecule, with the atomic coordinates as shown.  Then s/he wants the center
of mass of two subsets of those atoms.  Unless I misunderstood, this isn't a
particularly difficult task.


He said he wanted to divide the molecule into two parts based
somehow on the centre of mass previously calculated, which sounds
like the division isn't predetermined.

But yes, if you already know which atoms belong to each half,
then there's no difficulty.

Either way, the problem statement needs some refining before we
can help much more.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: getting the center of mass of each part of a molecule

2017-05-17 Thread jladasky
On Wednesday, May 17, 2017 at 12:14:10 AM UTC-7, Gregory Ewing wrote:
> I think the problem is ambiguous as stated. There are many planes
> you could pick through the centre of mass that divides the atoms
> into two groups. Some other rule is needed to decide which is the
> "right" one.

I took the OP at their word.  S/he wants the center of mass of the whole 
molecule, with the atomic coordinates as shown.  Then s/he wants the center of 
mass of two subsets of those atoms.  Unless I misunderstood, this isn't a 
particularly difficult task.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: getting the center of mass of each part of a molecule

2017-05-17 Thread Gregory Ewing

I think the problem is ambiguous as stated. There are many planes
you could pick through the centre of mass that divides the atoms
into two groups. Some other rule is needed to decide which is the
"right" one.

My guess is that what you have in mind involves finding the
"longest" axis of the molecule in some sense. That's easy to
determine visually, but not so easy when all you have to work
with is numbers.

One approach would be to find the axis around which the molecule
has the smallest moment of inertia. That involves finding the
eigenvectors of the rotational inertia matrix and picking the
one with the smallest eigenvalue.

--
Greg
--
https://mail.python.org/mailman/listinfo/python-list


Re: getting the center of mass of each part of a molecule

2017-05-16 Thread John Ladasky
On Monday, May 15, 2017 at 7:23:52 PM UTC-7, jeanbi...@gmail.com wrote:
> What may make this tricky is that the vinyl group can rotate at the point 
> where it attaches to the benzene ring so the full molecule may not lie in a 
> plane.

But the OP has coordinates for each atom which are used in the center of mass 
calculation for the whole molecule.  Why would the atoms be stationary for that 
calculation, and yet free to move in the calculation performed on a subset of 
the atoms?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: getting the center of mass of each part of a molecule

2017-05-16 Thread John Ladasky
On Monday, May 15, 2017 at 10:23:12 PM UTC-7, qasi...@gmail.com wrote:
> @Cameron:
> Thanks, I will try what you suggest. I am not sure that I'll tackle it 
> because I am new to python.

I teach programming to people with varying levels of expertise, from 
middle-school students to working professionals.  Do you program in any other 
languages?  What do you know how to do?  Can you write loops?

Why do you have a function named heavy_atoms() which takes all of your data and 
parses it internally, when you know that you sometimes want to work with 
subsets of that data?

Also, can you show us the rest of the program?  Right now you define a function 
that is never called, and it never returns anything either.

One final point: I think you have complicated your task by jumping straight 
into using Numpy arrays.  You may need to understand Numpy's vectorized 
function calls (the last line of your code).  If you want to select subsets of 
data from Numpy arrays, you could use Numpy's fancy indexing, but you have to 
understand that.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: getting the center of mass of each part of a molecule

2017-05-15 Thread qasimpars
@Cameron:
Thanks, I will try what you suggest. I am not sure that I'll tackle it because 
I am new to python.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: getting the center of mass of each part of a molecule

2017-05-15 Thread jeanbigboute
On Monday, May 15, 2017 at 1:30:05 PM UTC-7, qasi...@gmail.com wrote:
> Hi,
> 
> I need to get the center of mass (COM) of each half of the ligand shown in 
> the figure (https://i.stack.imgur.com/dtdul.png). I get the main COM all the 
> ligand, lets say it is close to C1 atom. ...

I don't quite follow your terminology.  A ligand is typically something that 
hangs onto  something - usually a metal atom or some other larger molecule.

It looks like you want the center of mass of the styrene molecule.  Why not 
consider it as a benzene ring (C6H6) with the vinyl group (CH2CH) as a ligand?  

The benzene group will have its c.o.m. in the middle of the ring, by symmetry.  
Make this the origin.  

The vinyl group's c.o.m can be calculated by the methods given in
http://hyperphysics.phy-astr.gsu.edu/hbase/cm.html

Then you can find the c.o.m of the whole molecule by considering it as two 
masses in a specific geometry.  This seems like the point of the exercise.

What may make this tricky is that the vinyl group can rotate at the point where 
it attaches to the benzene ring so the full molecule may not lie in a plane.  

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: getting the center of mass of each part of a molecule

2017-05-15 Thread Cameron Simpson

On 15May2017 13:29, qasimp...@gmail.com  wrote:
I need to get the center of mass (COM) of each half of the ligand shown in the 
figure (https://i.stack.imgur.com/dtdul.png). I get the main COM all the 
ligand, lets say it is close to C1 atom. In addition to the main COM of all 
the ligand, I need to find the COM of each half of the ligand. The atoms of 
the first part/half according to the main COM of the ligand are C2, C7, C8 and 
C9. As for the second part they are C3, C4, C5 and C6 atoms. The question is 
how can I divide the ligand in two parts according to the main COM and 
calculate the COM of each divided part (except for the atom closest to the 
main COM, C1)? By the way I have multiple ligands. The code should be user 
firendly.


Leaving aside that you are using numpy arrays, if sources like you need to 
partition an existing array into 2 parts around the dividing element (C1).


Figure out how to find the position of C1 in the array. If your atoms are 
unique in the sense that C1 != C2 even if they are both carbon atoms) you could 
use the .index method of a list (hoping numpy array support that). But 
otherwise, loop over the array until you find the element C1 and return the 
index. Write a short function for this purpose, eg (incomplete):


 def find_atom(atom, atoms):
   for i, a  in enumerate(atoms):
 if a is the target atom "atom":
   return i
   raise IndexError("no such atom")

Then all you need to do is:

 - figure out _which_ atom is your "C1"
 - locate it in the main array of atoms
 - extract the left and half subarrays

For the last part, remember that to get a sublist you can write L[a:b] to get 
all the elements of L from a up to but excluding b. And that omitting "a" 
implies index 0 and omitting "b" implies len(L).


The homework suggestion that the "code should be user firendly" I would take to 
imply that the last step should itself be a function, eg:


 def partition_atoms(atom, atoms):

which takes your target atom (C1) and the original array, calls find_atom to 
locate C1, and returns the left and right sublists.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: getting the center of mass of each part of a molecule

2017-05-15 Thread qasimpars
@Gary:
No, I don't have any algorithm. Well, I can define what I want:
1) The script will read the atom coordinates of the ligand from the input file 
sent in previous message.

2) It will calculate the center of mass (COM) for all the ligand atoms and find 
the ligand heavy atom closest to its COM.
I already do these two steps but 3. and 4.steps

3) The script should be able to seperate ligand atoms into two equal parts 
according to the main COM (COM for all atoms). Consider that the the main COM 
is reference point.

4) It should find the COM each of both equal parts.

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: getting the center of mass of each part of a molecule

2017-05-15 Thread jladasky
The last line of your function already calculates a center of mass for all 
atoms.  

How can you separate out that calculation into its own (one-line) function?

How can you send just a subset of your data to that new function?
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: getting the center of mass of each part of a molecule

2017-05-15 Thread Gary Herron

On 05/15/2017 01:29 PM, qasimp...@gmail.com wrote:

Hi,

I need to get the center of mass (COM) of each half of the ligand shown in the 
figure (https://i.stack.imgur.com/dtdul.png). I get the main COM all the 
ligand, lets say it is close to C1 atom. In addition to the main COM of all the 
ligand, I need to find the COM of each half of the ligand. The atoms of the 
first part/half according to the main COM of the ligand are C2, C7, C8 and C9. 
As for the second part they are C3, C4, C5 and C6 atoms. The question is how 
can I divide the ligand in two parts according to the main COM and calculate 
the COM of each divided part (except for the atom closest to the main COM, C1)? 
By the way I have multiple ligands. The code should be user firendly.

A short part of the input file is here:

1LIG C11   4.434   5.366   1.780
1LIG C22   4.317   5.301   1.940
1LIG C33   4.430   5.286   1.888
1LIG C44   4.380   4.942   2.467
1LIG C55   4.148   4.929   2.443

A short snippet of the code used to get the main COM is here:

def heavy_atoms(atoms, xyz, ligand="LIG"):
 ids   = np.arange(len(atoms))
 names = [(i[10:15].strip(),i[5:10].strip()) for i,j in atoms]

 # Ligand atoms
 lig_atoms = np.array([ rname == ligand and not aname.startswith('H') for 
aname,rname in names ])
 lig_xyz = xyz[lig_atoms,:]

 # The main COM
 lig_com = xyz[lig_atoms, :].mean(axis=0)



You seem to be asking a chemistry or biochemistry question on this 
Python programming list.  We're a diverse group, but still, that seems 
to be a vast mismatch.   Do you have any hint of an algorithm that will 
do what you want?  Can you find one somewhere, or define one yourself?   
Once you have an algorithm, it would be appropriate to ask here for help 
in translating it into a Python program.



Gary Herron


--
Dr. Gary Herron
Professor of Computer Science
DigiPen Institute of Technology
(425) 895-4418

--
https://mail.python.org/mailman/listinfo/python-list