Re: [Chimera-users] Recursive structure matching and acquisition of descriptive numbers
Hi! Since you are getting lists of atoms back, you only need to do some attribute access (rather than method calling)! Every chimera.Atom object has an attribute called molecule: a reference to its parent chimera.Molecule. chimera.Molecule objects have an attribute called 'name', but sometimes this is not very informative (depends on your input), so you need to resort to the pdb filename, stored in the first element of the openedAs tuple. In code, this looks like this: for atoms1, atoms2, rmsd, fullRmsd in match(CP_BEST, [ref, sims], defaults[MATRIX], "nw", defaults[GAP_OPEN], defaults[GAP_EXTEND]): molecule1 = atoms1[0].molecule # any atom from the list will do molecule2 = atoms2[0].molecule print molecule1.name, "\t", molecule2.name, "\t", rmsd # molecule1.openedAs[0] will also work here I don't know if atoms1 comes consistently from the reference molecule, but I'd guess it does. Hope it helps!
Thanks Jaime — exactly right. I realized that the “atoms1, atoms2” in my original example didn’t really give any indication of which atoms were which, which is why in my later examples I changed to "simAtoms, refAtoms”, so it’s actually “atoms2” that are the reference atoms. —Eric
On Sep 22, 2016, at 11:45 AM, Jaime Rodríguez-Guerra <jaime.rodriguezguerra@uab.cat> wrote:
Hi!
Since you are getting lists of atoms back, you only need to do some attribute access (rather than method calling)!
Every chimera.Atom object has an attribute called molecule: a reference to its parent chimera.Molecule. chimera.Molecule objects have an attribute called 'name', but sometimes this is not very informative (depends on your input), so you need to resort to the pdb filename, stored in the first element of the openedAs tuple.
In code, this looks like this:
for atoms1, atoms2, rmsd, fullRmsd in match(CP_BEST, [ref, sims], defaults[MATRIX], "nw", defaults[GAP_OPEN], defaults[GAP_EXTEND]): molecule1 = atoms1[0].molecule # any atom from the list will do molecule2 = atoms2[0].molecule print molecule1.name, "\t", molecule2.name, "\t", rmsd # molecule1.openedAs[0] will also work here
I don't know if atoms1 comes consistently from the reference molecule, but I'd guess it does.
Hope it helps! _______________________________________________ Chimera-users mailing list: Chimera-users@cgl.ucsf.edu Manage subscription: http://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users
That was exactly what I was after thanks! I figured the object orientation should provide that somewhere but was barking up slightly the wrong tree! Thank you all for all your help - definitely wouldn't have been able to do it without you! If it's of any interest, or it helps for any future questions where you might want to refer back to code segments, I've put the more-or-less-finished script in this paste: http://pastebin.com/xJNSWJGq Joe Healey M.Sc. B.Sc. (Hons) PhD Student MOAC CDT, Senate House University of Warwick Coventry CV47AL Mob: +44 (0) 7536 042620 | Email: J.R.J.Healey@warwick.ac.uk Jointly working in: Waterfield Lab<http://www2.warwick.ac.uk/fac/med/research/tsm/microinfect/staff/waterfieldlab/> (WMS Microbiology and Infection Unit) and the Gibson Lab<http://www2.warwick.ac.uk/fac/sci/chemistry/research/gibson/gibsongroup/> (Warwick Chemistry) Twitter: @JRJHealey<https://twitter.com/JRJHealey> | Website: MOAC Page<http://www2.warwick.ac.uk/fac/sci/moac/people/students/2013/joseph_healey> ________________________________ From: Eric Pettersen <pett@cgl.ucsf.edu> Sent: 22 September 2016 20:54:35 To: Jaime Rodríguez-Guerra Cc: chimera-users@cgl.ucsf.edu; Healey, Joe Subject: Re: [Chimera-users] Recursive structure matching and acquisition of descriptive numbers Thanks Jaime — exactly right. I realized that the “atoms1, atoms2” in my original example didn’t really give any indication of which atoms were which, which is why in my later examples I changed to "simAtoms, refAtoms”, so it’s actually “atoms2” that are the reference atoms. —Eric
On Sep 22, 2016, at 11:45 AM, Jaime Rodríguez-Guerra <jaime.rodriguezguerra@uab.cat> wrote:
Hi!
Since you are getting lists of atoms back, you only need to do some attribute access (rather than method calling)!
Every chimera.Atom object has an attribute called molecule: a reference to its parent chimera.Molecule. chimera.Molecule objects have an attribute called 'name', but sometimes this is not very informative (depends on your input), so you need to resort to the pdb filename, stored in the first element of the openedAs tuple.
In code, this looks like this:
for atoms1, atoms2, rmsd, fullRmsd in match(CP_BEST, [ref, sims], defaults[MATRIX], "nw", defaults[GAP_OPEN], defaults[GAP_EXTEND]): molecule1 = atoms1[0].molecule # any atom from the list will do molecule2 = atoms2[0].molecule print molecule1.name, "\t", molecule2.name, "\t", rmsd # molecule1.openedAs[0] will also work here
I don't know if atoms1 comes consistently from the reference molecule, but I'd guess it does.
Hope it helps! _______________________________________________ Chimera-users mailing list: Chimera-users@cgl.ucsf.edu Manage subscription: http://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users
Hi Joe! You're welcome! Glad to see you got it working. I've reviewed your code and would want to point out some details that might be helpful to you in the future, though. These are mostly style-related things, but those will contribute to a cleaner reading experience! 1. You don't need backslashes if you're inside parenthesis. So, in all those parse_argument lines, you can safely delete them. Related to this, you can wrap imports with parenthesis, so that backslashes are not needed. 2. Tuple unpacking does not need parenthesis in you're dealing with 1D-tuples. Only needed if you are dealing with more than one dimension (ie, (animal, fruit), sport = [['tiger', 'pear'], 'soccer'] 3. Since you are opening files with the "with" context manager, you don't need to manually close the file later. It's closed automatically as soon as you leave that with block. 4. Lines 166-170 could be replaced with a (cleaner, but not necessarily more performant) glob.glob() call. Check it out to see if it satisfies your requirements. 5. While you are at it, take a look at the PEP8 docs and the Google Python style guide. You don't need to follow all the rules, but they are really helpful in bringing consistency to your own style! That's it! Hope you don't mind these pieces of advice :) Cheers, Jaime. 2016-09-23 11:27 GMT+02:00 Healey, Joe <J.R.J.Healey@warwick.ac.uk>:
That was exactly what I was after thanks! I figured the object orientation should provide that somewhere but was barking up slightly the wrong tree!
Thank you all for all your help - definitely wouldn't have been able to do it without you!
If it's of any interest, or it helps for any future questions where you might want to refer back to code segments, I've put the more-or-less-finished script in this paste:
Joe Healey
M.Sc. B.Sc. (Hons) PhD Student MOAC CDT, Senate House University of Warwick Coventry CV47AL Mob: +44 (0) 7536 042620 | Email: J.R.J.Healey@warwick.ac.uk
Jointly working in: Waterfield Lab (WMS Microbiology and Infection Unit) and the Gibson Lab (Warwick Chemistry)
Twitter: @JRJHealey | Website: MOAC Page ________________________________ From: Eric Pettersen <pett@cgl.ucsf.edu> Sent: 22 September 2016 20:54:35 To: Jaime Rodríguez-Guerra Cc: chimera-users@cgl.ucsf.edu; Healey, Joe Subject: Re: [Chimera-users] Recursive structure matching and acquisition of descriptive numbers
Thanks Jaime — exactly right. I realized that the “atoms1, atoms2” in my original example didn’t really give any indication of which atoms were which, which is why in my later examples I changed to "simAtoms, refAtoms”, so it’s actually “atoms2” that are the reference atoms.
—Eric
On Sep 22, 2016, at 11:45 AM, Jaime Rodríguez-Guerra <jaime.rodriguezguerra@uab.cat> wrote:
Hi!
Since you are getting lists of atoms back, you only need to do some attribute access (rather than method calling)!
Every chimera.Atom object has an attribute called molecule: a reference to its parent chimera.Molecule. chimera.Molecule objects have an attribute called 'name', but sometimes this is not very informative (depends on your input), so you need to resort to the pdb filename, stored in the first element of the openedAs tuple.
In code, this looks like this:
for atoms1, atoms2, rmsd, fullRmsd in match(CP_BEST, [ref, sims], defaults[MATRIX], "nw", defaults[GAP_OPEN], defaults[GAP_EXTEND]): molecule1 = atoms1[0].molecule # any atom from the list will do molecule2 = atoms2[0].molecule print molecule1.name, "\t", molecule2.name, "\t", rmsd # molecule1.openedAs[0] will also work here
I don't know if atoms1 comes consistently from the reference molecule, but I'd guess it does.
Hope it helps! _______________________________________________ Chimera-users mailing list: Chimera-users@cgl.ucsf.edu Manage subscription: http://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users
Not at all! Much appreciated, as I think I mentioned, this is my first go at writing anything remotely complex in python (and not a bad turn out for about a week I don't think...) A lot of the mess comes from copying functional bits from StackOverflow in the interests of just getting it working first, and making it pretty second as I'm sure you can appreciate (you'd hate to see my LaTeX preamble)! Not needed to close the file with 'with' is useful to know (takes some of the headache out of knowing where to place the close). I'll certainly make the tidy ups you've suggested, for my own learning. Thanks again, Joe :) Joe Healey M.Sc. B.Sc. (Hons) PhD Student MOAC CDT, Senate House University of Warwick Coventry CV47AL Mob: +44 (0) 7536 042620 | Email: J.R.J.Healey@warwick.ac.uk Jointly working in: Waterfield Lab<http://www2.warwick.ac.uk/fac/med/research/tsm/microinfect/staff/waterfieldlab/> (WMS Microbiology and Infection Unit) and the Gibson Lab<http://www2.warwick.ac.uk/fac/sci/chemistry/research/gibson/gibsongroup/> (Warwick Chemistry) Twitter: @JRJHealey<https://twitter.com/JRJHealey> | Website: MOAC Page<http://www2.warwick.ac.uk/fac/sci/moac/people/students/2013/joseph_healey> ________________________________ From: Jaime Rodríguez-Guerra <jaime.rodriguezguerra@uab.cat> Sent: 23 September 2016 10:56:38 To: Healey, Joe Cc: Eric Pettersen; Jaime Rodríguez-Guerra; chimera-users@cgl.ucsf.edu Subject: Re: [Chimera-users] Recursive structure matching and acquisition of descriptive numbers Hi Joe! You're welcome! Glad to see you got it working. I've reviewed your code and would want to point out some details that might be helpful to you in the future, though. These are mostly style-related things, but those will contribute to a cleaner reading experience! 1. You don't need backslashes if you're inside parenthesis. So, in all those parse_argument lines, you can safely delete them. Related to this, you can wrap imports with parenthesis, so that backslashes are not needed. 2. Tuple unpacking does not need parenthesis in you're dealing with 1D-tuples. Only needed if you are dealing with more than one dimension (ie, (animal, fruit), sport = [['tiger', 'pear'], 'soccer'] 3. Since you are opening files with the "with" context manager, you don't need to manually close the file later. It's closed automatically as soon as you leave that with block. 4. Lines 166-170 could be replaced with a (cleaner, but not necessarily more performant) glob.glob() call. Check it out to see if it satisfies your requirements. 5. While you are at it, take a look at the PEP8 docs and the Google Python style guide. You don't need to follow all the rules, but they are really helpful in bringing consistency to your own style! That's it! Hope you don't mind these pieces of advice :) Cheers, Jaime. 2016-09-23 11:27 GMT+02:00 Healey, Joe <J.R.J.Healey@warwick.ac.uk>:
That was exactly what I was after thanks! I figured the object orientation should provide that somewhere but was barking up slightly the wrong tree!
Thank you all for all your help - definitely wouldn't have been able to do it without you!
If it's of any interest, or it helps for any future questions where you might want to refer back to code segments, I've put the more-or-less-finished script in this paste:
Joe Healey
M.Sc. B.Sc. (Hons) PhD Student MOAC CDT, Senate House University of Warwick Coventry CV47AL Mob: +44 (0) 7536 042620 | Email: J.R.J.Healey@warwick.ac.uk
Jointly working in: Waterfield Lab (WMS Microbiology and Infection Unit) and the Gibson Lab (Warwick Chemistry)
Twitter: @JRJHealey | Website: MOAC Page ________________________________ From: Eric Pettersen <pett@cgl.ucsf.edu> Sent: 22 September 2016 20:54:35 To: Jaime Rodríguez-Guerra Cc: chimera-users@cgl.ucsf.edu; Healey, Joe Subject: Re: [Chimera-users] Recursive structure matching and acquisition of descriptive numbers
Thanks Jaime — exactly right. I realized that the “atoms1, atoms2” in my original example didn’t really give any indication of which atoms were which, which is why in my later examples I changed to "simAtoms, refAtoms”, so it’s actually “atoms2” that are the reference atoms.
—Eric
On Sep 22, 2016, at 11:45 AM, Jaime Rodríguez-Guerra <jaime.rodriguezguerra@uab.cat> wrote:
Hi!
Since you are getting lists of atoms back, you only need to do some attribute access (rather than method calling)!
Every chimera.Atom object has an attribute called molecule: a reference to its parent chimera.Molecule. chimera.Molecule objects have an attribute called 'name', but sometimes this is not very informative (depends on your input), so you need to resort to the pdb filename, stored in the first element of the openedAs tuple.
In code, this looks like this:
for atoms1, atoms2, rmsd, fullRmsd in match(CP_BEST, [ref, sims], defaults[MATRIX], "nw", defaults[GAP_OPEN], defaults[GAP_EXTEND]): molecule1 = atoms1[0].molecule # any atom from the list will do molecule2 = atoms2[0].molecule print molecule1.name, "\t", molecule2.name, "\t", rmsd # molecule1.openedAs[0] will also work here
I don't know if atoms1 comes consistently from the reference molecule, but I'd guess it does.
Hope it helps! _______________________________________________ Chimera-users mailing list: Chimera-users@cgl.ucsf.edu Manage subscription: http://plato.cgl.ucsf.edu/mailman/listinfo/chimera-users
participants (3)
-
Eric Pettersen
-
Healey, Joe
-
Jaime Rodríguez-Guerra