From: Pawel <pa...@gm...> - 2013-11-08 12:30:36
|
Hi, I've continued to investigate and have gotten even more confused. This script: from numpy import * import sys cmd.delete("all") cmd.load( "../4lzt_quasi.pdb", "full") cmd.create("anew", "full", 1, 1) print "First 3 shifts: ", nm[0:3], "\n" cmd.alter_state(1,"anew" , "x,y,z = x+nm[(ID-1)*3], y+nm[(ID-1)*3+1], z+nm[(ID-1)*3+2]") xyz1=[] cmd.iterate_state(1, 'full & id 5', 'xyz1.append([x,y,z])') xyz2=[] cmd.iterate_state(1, 'anew & id 1', 'xyz2.append([x,y,z])') print "Coords of full id 5:", array(xyz1) print "Coords of anew id 1:", array(xyz2) print "Shift between full id5 and anew id1:", array(xyz1)-array(xyz2), "\n" xyz1=[] cmd.iterate_state(1, 'full & resid 1 & name ca ', 'xyz1.append([x,y,z])') xyz2=[] cmd.iterate_state(1, 'anew & resid 1 & name ca ', 'xyz2.append([x,y,z])') print "Coords of full resid1 name ca: ", array(xyz1) print "Coords of full resid1 name ca: ", array(xyz2) print "Shift between full id5 and anew id1: ", array(xyz1)-array(xyz2) print "\n" yields: PyMOL>run pymoltest1.py First 3 shifts: [-0.1263 0.0152 -0.0444] Coords of full id 5: [[ 2.539 5.619 12.706]] Coords of anew id 1: [[ 2.4127 5.6342 12.6616]] Shift between full id5 and anew id1: [[ 0.1263 -0.0152 0.0444]] Coords of full resid1 name ca: [[ 2.539 5.619 12.706]] Coords of full resid1 name ca: [[ 2.4127 5.6342 12.6616]] Shift between full id5 and anew id1: [[ 0.1263 -0.0152 0.0444]] What I see from this is: - the first set of shifts is applied to the CA atom which is the fifth atom in the original pdb file and somehow becomes the second atom in the object created with cmd.create - the object created by cmd.create has atom id's spanning from 0 to N-1 (original object had atom ids from 1 to N) I would like to know what is happening but, more importantly, what is the best way to apply the shifts vector "nm" to the atoms in the original object where the shifts in "nm" are according to the order in the pdb file. Thanks! Pawel |
From: Pawel <pa...@gm...> - 2013-11-14 14:21:28
|
Hi Pymol users, I posted a question last week (attached below) that didn't generate any responses so I'm thinking maybe I was being too specific. So I'd like to restate the problem in a much more general way: I'm trying to apply a set of shifts sequentially from a numpy array to each atom in the structure. The basic way I try to do this is: cmd.load( "../4lzt_quasi.pdb", "full") cmd.create("anew", "full", 1, 1) cmd.alter_state(1,"anew" , "x,y,z = x+nm[(ID-1)*3], y+nm[(ID-1)*3+1], z+nm[(ID-1)*3+2]") but it seems that the create command changes the IDs of the atoms so that the shifts are now applied to the wrong atoms (eg a CA atom with ID=5 has ID=1 in the newly created object). So the question is: - does anyone know how and why the ID's are change? (then I could reorder the shifts in my array to match the new object) - or is there a better way to apply shifts to the atoms? Thanks! Pawel -------- Original Message -------- Subject: Re: [PyMOL] discrepancy between python and commandline script Date: Fri, 08 Nov 2013 07:30:28 -0500 From: Pawel <pa...@gm...> To: Pawel Janowski <pa...@gm...>, pym...@li... Hi, I've continued to investigate and have gotten even more confused. This script: from numpy import * import sys cmd.delete("all") cmd.load( "../4lzt_quasi.pdb", "full") cmd.create("anew", "full", 1, 1) print "First 3 shifts: ", nm[0:3], "\n" cmd.alter_state(1,"anew" , "x,y,z = x+nm[(ID-1)*3], y+nm[(ID-1)*3+1], z+nm[(ID-1)*3+2]") xyz1=[] cmd.iterate_state(1, 'full & id 5', 'xyz1.append([x,y,z])') xyz2=[] cmd.iterate_state(1, 'anew & id 1', 'xyz2.append([x,y,z])') print "Coords of full id 5:", array(xyz1) print "Coords of anew id 1:", array(xyz2) print "Shift between full id5 and anew id1:", array(xyz1)-array(xyz2), "\n" xyz1=[] cmd.iterate_state(1, 'full & resid 1 & name ca ', 'xyz1.append([x,y,z])') xyz2=[] cmd.iterate_state(1, 'anew & resid 1 & name ca ', 'xyz2.append([x,y,z])') print "Coords of full resid1 name ca: ", array(xyz1) print "Coords of full resid1 name ca: ", array(xyz2) print "Shift between full id5 and anew id1: ", array(xyz1)-array(xyz2) print "\n" yields: PyMOL>run pymoltest1.py First 3 shifts: [-0.1263 0.0152 -0.0444] Coords of full id 5: [[ 2.539 5.619 12.706]] Coords of anew id 1: [[ 2.4127 5.6342 12.6616]] Shift between full id5 and anew id1: [[ 0.1263 -0.0152 0.0444]] Coords of full resid1 name ca: [[ 2.539 5.619 12.706]] Coords of full resid1 name ca: [[ 2.4127 5.6342 12.6616]] Shift between full id5 and anew id1: [[ 0.1263 -0.0152 0.0444]] What I see from this is: - the first set of shifts is applied to the CA atom which is the fifth atom in the original pdb file and somehow becomes the second atom in the object created with cmd.create - the object created by cmd.create has atom id's spanning from 0 to N-1 (original object had atom ids from 1 to N) I would like to know what is happening but, more importantly, what is the best way to apply the shifts vector "nm" to the atoms in the original object where the shifts in "nm" are according to the order in the pdb file. Thanks! Pawel -------- Original Message -------- Subject: discrepancy between python and commandline script Date: Thu, 07 Nov 2013 18:55:17 -0500 From: Pawel <pa...@gm...> To: pym...@li... Hello, I'm trying to understand what seems like an inconsistency between PyMOL commandline and python scripts. I have the following commandline script: delete all load ../4lzt_quasi.pdb, full cmd.create("anew", "full", 1, 1) cmd.alter_state(1,"anew" , "x,y,z = x+nm[(ID-1)*3], y+nm[(ID-1)*3+1], z+nm[(ID-1)*3+2]") iterate_state 1, full & id 1, print x, y,z iterate_state 1, anew & id 1, print x, y,z Which I then run: PyMOL>@pymoltest1.txt ... PyMOL>iterate_state 1, full & id 1, print x, y,z 2.69099998474 4.58500003815 13.6999998093 IterateState: iterated over 1 atom coordinate states. PyMOL>iterate_state 1, anew & id 1, print x, y,z 2.41267466545 5.63420581818 12.6615524292 IterateState: iterated over 1 atom coordinate states. Now I have this python script: cmd.delete( all) cmd.load( "../4lzt_quasi.pdb", "full") cmd.create("anew", "full", 1, 1) cmd.alter_state(1,"anew" , "x,y,z = x+nm[(ID-1)*3], y+nm[(ID-1)*3+1], z+nm[(ID-1)*3+2]") xyz1=[] cmd.iterate_state(1, 'full & id 1', 'xyz1.append([x,y,z])') xyz2=[] cmd.iterate_state(1, 'anew & id 1', 'xyz2.append([x,y,z])') print xyz1 print xyz2 Which I run: PyMOL>run pymoltest1.py [[2.690999984741211, 4.585000038146973, 13.699999809265137]] [[2.5646746158599854, 4.600205898284912, 13.65555191040039]] Why am I getting different coordinates for the second atom? The second set of coordinates from the first script are actually the coordinates of the 5th atom in my structure (CA of a LYS). I'm guessing that the alter_state command is somehow doing something different in one and the other case but it's hard to understand why. Thanks for the help, Pawel |
From: Thomas H. <sp...@us...> - 2013-11-14 19:08:02
|
Hi Pawel, sorry that you didn't get a reply. Some hints: - it looks like IDs are always reset with "cmd.create", but with "cmd.copy" there are not http://pymolwiki.org/index.php/Copy - "ID" is neither necessarily unique nor contiguous (for example the TER record in a PDB file has it's own ID). You might use "index" instead. The "index" will change if you delete atoms or change the order (cmd.sort). Set retain_order=1 to prevent automatic sorting. http://pymolwiki.org/index.php/Retain_order - alter_state is right now the best option to load coordinates. There is an experimental and partly broken "cmd.load_coords" function (it's fixed in the latest SVN version). http://pymolwiki.org/index.php/Get_Coordinates_I Hope that helps. Cheers, Thomas On 14 Nov 2013, at 09:21, Pawel <pa...@gm...> wrote: > Hi Pymol users, > > I posted a question last week (attached below) that didn't generate any responses so I'm thinking maybe I was being too specific. So I'd like to restate the problem in a much more general way: I'm trying to apply a set of shifts sequentially from a numpy array to each atom in the structure. The basic way I try to do this is: > > cmd.load( "../4lzt_quasi.pdb", "full") > cmd.create("anew", "full", 1, 1) > cmd.alter_state(1,"anew" , "x,y,z = x+nm[(ID-1)*3], y+nm[(ID-1)*3+1], z+nm[(ID-1)*3+2]") > > but it seems that the create command changes the IDs of the atoms so that the shifts are now applied to the wrong atoms (eg a CA atom with ID=5 has ID=1 in the newly created object). > > So the question is: > > - does anyone know how and why the ID's are change? (then I could reorder the shifts in my array to match the new object) > - or is there a better way to apply shifts to the atoms? > > Thanks! > Pawel > > > > -------- Original Message -------- > Subject: Re: [PyMOL] discrepancy between python and commandline script > Date: Fri, 08 Nov 2013 07:30:28 -0500 > From: Pawel <pa...@gm...> > To: Pawel Janowski <pa...@gm...>, pym...@li... > > Hi, > > I've continued to investigate and have gotten even more confused. This script: > > from numpy import * > import sys > > cmd.delete("all") > cmd.load( "../4lzt_quasi.pdb", "full") > cmd.create("anew", "full", 1, 1) > print "First 3 shifts: ", nm[0:3], "\n" > cmd.alter_state(1,"anew" , "x,y,z = x+nm[(ID-1)*3], y+nm[(ID-1)*3+1], z+nm[(ID-1)*3+2]") > > xyz1=[] > cmd.iterate_state(1, 'full & id 5', 'xyz1.append([x,y,z])') > xyz2=[] > cmd.iterate_state(1, 'anew & id 1', 'xyz2.append([x,y,z])') > print "Coords of full id 5:", array(xyz1) > print "Coords of anew id 1:", array(xyz2) > print "Shift between full id5 and anew id1:", array(xyz1)-array(xyz2), "\n" > > xyz1=[] > cmd.iterate_state(1, 'full & resid 1 & name ca ', 'xyz1.append([x,y,z])') > xyz2=[] > cmd.iterate_state(1, 'anew & resid 1 & name ca ', 'xyz2.append([x,y,z])') > print "Coords of full resid1 name ca: ", array(xyz1) > print "Coords of full resid1 name ca: ", array(xyz2) > print "Shift between full id5 and anew id1: ", array(xyz1)-array(xyz2) > print "\n" > > yields: > > PyMOL>run pymoltest1.py > First 3 shifts: [-0.1263 0.0152 -0.0444] > > Coords of full id 5: [[ 2.539 5.619 12.706]] > Coords of anew id 1: [[ 2.4127 5.6342 12.6616]] > Shift between full id5 and anew id1: [[ 0.1263 -0.0152 0.0444]] > > Coords of full resid1 name ca: [[ 2.539 5.619 12.706]] > Coords of full resid1 name ca: [[ 2.4127 5.6342 12.6616]] > Shift between full id5 and anew id1: [[ 0.1263 -0.0152 0.0444]] > What I see from this is: > - the first set of shifts is applied to the CA atom which is the fifth atom in the original pdb file and somehow becomes the second atom in the object created with cmd.create > - the object created by cmd.create has atom id's spanning from 0 to N-1 (original object had atom ids from 1 to N) > > I would like to know what is happening but, more importantly, what is the best way to apply the shifts vector "nm" to the atoms in the original object where the shifts in "nm" are according to the order in the pdb file. > > Thanks! > Pawel > > > -------- Original Message -------- > Subject: discrepancy between python and commandline script > Date: Thu, 07 Nov 2013 18:55:17 -0500 > From: Pawel <pa...@gm...> > To: pym...@li... > > Hello, > > I'm trying to understand what seems like an inconsistency between PyMOL commandline and python scripts. I have the following commandline script: > > delete all > load ../4lzt_quasi.pdb, full > cmd.create("anew", "full", 1, 1) > cmd.alter_state(1,"anew" , "x,y,z = x+nm[(ID-1)*3], y+nm[(ID-1)*3+1], z+nm[(ID-1)*3+2]") > iterate_state 1, full & id 1, print x, y,z > iterate_state 1, anew & id 1, print x, y,z > Which I then run: > > PyMOL>@pymoltest1.txt > ... > PyMOL>iterate_state 1, full & id 1, print x, y,z > 2.69099998474 4.58500003815 13.6999998093 > IterateState: iterated over 1 atom coordinate states. > PyMOL>iterate_state 1, anew & id 1, print x, y,z > 2.41267466545 5.63420581818 12.6615524292 > IterateState: iterated over 1 atom coordinate states. > Now I have this python script: > cmd.delete( all) > cmd.load( "../4lzt_quasi.pdb", "full") > cmd.create("anew", "full", 1, 1) > cmd.alter_state(1,"anew" , "x,y,z = x+nm[(ID-1)*3], y+nm[(ID-1)*3+1], z+nm[(ID-1)*3+2]") > xyz1=[] > cmd.iterate_state(1, 'full & id 1', 'xyz1.append([x,y,z])') > xyz2=[] > cmd.iterate_state(1, 'anew & id 1', 'xyz2.append([x,y,z])') > print xyz1 > print xyz2 > Which I run: > PyMOL>run pymoltest1.py > [[2.690999984741211, 4.585000038146973, 13.699999809265137]] > [[2.5646746158599854, 4.600205898284912, 13.65555191040039]] > Why am I getting different coordinates for the second atom? The second set of coordinates from the first script are actually the coordinates of the 5th atom in my structure (CA of a LYS). I'm guessing that the alter_state command is somehow doing something different in one and the other case but it's hard to understand why. > > Thanks for the help, > Pawel |
From: Pawel <pa...@gm...> - 2013-11-14 20:04:02
|
Thanks Thomas! That helped greatly. Best, Pawel On 11/14/2013 02:07 PM, Thomas Holder wrote: > Hi Pawel, > > sorry that you didn't get a reply. Some hints: > > - it looks like IDs are always reset with "cmd.create", but with "cmd.copy" there are not > > http://pymolwiki.org/index.php/Copy > > - "ID" is neither necessarily unique nor contiguous (for example the TER record in a PDB file has it's own ID). You might use "index" instead. The "index" will change if you delete atoms or change the order (cmd.sort). Set retain_order=1 to prevent automatic sorting. > > http://pymolwiki.org/index.php/Retain_order > > - alter_state is right now the best option to load coordinates. There is an experimental and partly broken "cmd.load_coords" function (it's fixed in the latest SVN version). > > http://pymolwiki.org/index.php/Get_Coordinates_I > > Hope that helps. > > Cheers, > Thomas > > On 14 Nov 2013, at 09:21, Pawel <pa...@gm...> wrote: > >> Hi Pymol users, >> >> I posted a question last week (attached below) that didn't generate any responses so I'm thinking maybe I was being too specific. So I'd like to restate the problem in a much more general way: I'm trying to apply a set of shifts sequentially from a numpy array to each atom in the structure. The basic way I try to do this is: >> >> cmd.load( "../4lzt_quasi.pdb", "full") >> cmd.create("anew", "full", 1, 1) >> cmd.alter_state(1,"anew" , "x,y,z = x+nm[(ID-1)*3], y+nm[(ID-1)*3+1], z+nm[(ID-1)*3+2]") >> >> but it seems that the create command changes the IDs of the atoms so that the shifts are now applied to the wrong atoms (eg a CA atom with ID=5 has ID=1 in the newly created object). >> >> So the question is: >> >> - does anyone know how and why the ID's are change? (then I could reorder the shifts in my array to match the new object) >> - or is there a better way to apply shifts to the atoms? >> >> Thanks! >> Pawel >> >> >> >> -------- Original Message -------- >> Subject: Re: [PyMOL] discrepancy between python and commandline script >> Date: Fri, 08 Nov 2013 07:30:28 -0500 >> From: Pawel <pa...@gm...> >> To: Pawel Janowski <pa...@gm...>, pym...@li... >> >> Hi, >> >> I've continued to investigate and have gotten even more confused. This script: >> >> from numpy import * >> import sys >> >> cmd.delete("all") >> cmd.load( "../4lzt_quasi.pdb", "full") >> cmd.create("anew", "full", 1, 1) >> print "First 3 shifts: ", nm[0:3], "\n" >> cmd.alter_state(1,"anew" , "x,y,z = x+nm[(ID-1)*3], y+nm[(ID-1)*3+1], z+nm[(ID-1)*3+2]") >> >> xyz1=[] >> cmd.iterate_state(1, 'full & id 5', 'xyz1.append([x,y,z])') >> xyz2=[] >> cmd.iterate_state(1, 'anew & id 1', 'xyz2.append([x,y,z])') >> print "Coords of full id 5:", array(xyz1) >> print "Coords of anew id 1:", array(xyz2) >> print "Shift between full id5 and anew id1:", array(xyz1)-array(xyz2), "\n" >> >> xyz1=[] >> cmd.iterate_state(1, 'full & resid 1 & name ca ', 'xyz1.append([x,y,z])') >> xyz2=[] >> cmd.iterate_state(1, 'anew & resid 1 & name ca ', 'xyz2.append([x,y,z])') >> print "Coords of full resid1 name ca: ", array(xyz1) >> print "Coords of full resid1 name ca: ", array(xyz2) >> print "Shift between full id5 and anew id1: ", array(xyz1)-array(xyz2) >> print "\n" >> >> yields: >> >> PyMOL>run pymoltest1.py >> First 3 shifts: [-0.1263 0.0152 -0.0444] >> >> Coords of full id 5: [[ 2.539 5.619 12.706]] >> Coords of anew id 1: [[ 2.4127 5.6342 12.6616]] >> Shift between full id5 and anew id1: [[ 0.1263 -0.0152 0.0444]] >> >> Coords of full resid1 name ca: [[ 2.539 5.619 12.706]] >> Coords of full resid1 name ca: [[ 2.4127 5.6342 12.6616]] >> Shift between full id5 and anew id1: [[ 0.1263 -0.0152 0.0444]] >> What I see from this is: >> - the first set of shifts is applied to the CA atom which is the fifth atom in the original pdb file and somehow becomes the second atom in the object created with cmd.create >> - the object created by cmd.create has atom id's spanning from 0 to N-1 (original object had atom ids from 1 to N) >> >> I would like to know what is happening but, more importantly, what is the best way to apply the shifts vector "nm" to the atoms in the original object where the shifts in "nm" are according to the order in the pdb file. >> >> Thanks! >> Pawel >> >> >> -------- Original Message -------- >> Subject: discrepancy between python and commandline script >> Date: Thu, 07 Nov 2013 18:55:17 -0500 >> From: Pawel <pa...@gm...> >> To: pym...@li... >> >> Hello, >> >> I'm trying to understand what seems like an inconsistency between PyMOL commandline and python scripts. I have the following commandline script: >> >> delete all >> load ../4lzt_quasi.pdb, full >> cmd.create("anew", "full", 1, 1) >> cmd.alter_state(1,"anew" , "x,y,z = x+nm[(ID-1)*3], y+nm[(ID-1)*3+1], z+nm[(ID-1)*3+2]") >> iterate_state 1, full & id 1, print x, y,z >> iterate_state 1, anew & id 1, print x, y,z >> Which I then run: >> >> PyMOL>@pymoltest1.txt >> ... >> PyMOL>iterate_state 1, full & id 1, print x, y,z >> 2.69099998474 4.58500003815 13.6999998093 >> IterateState: iterated over 1 atom coordinate states. >> PyMOL>iterate_state 1, anew & id 1, print x, y,z >> 2.41267466545 5.63420581818 12.6615524292 >> IterateState: iterated over 1 atom coordinate states. >> Now I have this python script: >> cmd.delete( all) >> cmd.load( "../4lzt_quasi.pdb", "full") >> cmd.create("anew", "full", 1, 1) >> cmd.alter_state(1,"anew" , "x,y,z = x+nm[(ID-1)*3], y+nm[(ID-1)*3+1], z+nm[(ID-1)*3+2]") >> xyz1=[] >> cmd.iterate_state(1, 'full & id 1', 'xyz1.append([x,y,z])') >> xyz2=[] >> cmd.iterate_state(1, 'anew & id 1', 'xyz2.append([x,y,z])') >> print xyz1 >> print xyz2 >> Which I run: >> PyMOL>run pymoltest1.py >> [[2.690999984741211, 4.585000038146973, 13.699999809265137]] >> [[2.5646746158599854, 4.600205898284912, 13.65555191040039]] >> Why am I getting different coordinates for the second atom? The second set of coordinates from the first script are actually the coordinates of the 5th atom in my structure (CA of a LYS). I'm guessing that the alter_state command is somehow doing something different in one and the other case but it's hard to understand why. >> >> Thanks for the help, >> Pawel |