How to : Access chain properties such as chain ID. Access particle properties.
Hi list,
I am wondering what properties are attached to the various levels of a hierarchy and how to retrieve it. As an example, I would like to know how to get the one-character-code that is attached to a chain.
I have the feeling, this is not strictly feasible, though it is possible to get it as the last character in the particle name of the chain :
import IMP import IMP.atom
m=IMP.Model() struct_file_name = "/Users/schwarz/DATA/myPDB/1K8K.pdb" struct1k8k=IMP.atom.read_pdb(struct_file_name,m) c0=struct1k8k.get_child(0) print c0.get_name()
Will result in 'Chain A' being output. Looking at the other properties stored in my c0 chain, I see that everything seems to be integer, including a "chain" attribute that I try to access through
chainKey = c0.get_int_attributes()[2] c0.get_value(chainKey)
which results in the integer 65 being output...
My questions now : 1. Is there a way to get directly the one letter code of a chain ? 2. If not, is there a guaranty that the letter used in the particle name will always reflect the chain ID, or is there a fixed mapping between the value of the chainKey attribute and the chain one letter code ? 3. Is there a nicer way to get a keyType for instance from its string ? In my example, I retrieved chainKey as the third element of the integer keys list returned by get_int_attributes(), this is not very satisfying, and I thought of resorting to a function such as :
def getChainKey( chain ): for k in chain.get_int_attributes() : if k.get_string() == 'chain' : return k return None
Still, I wonder if there is an IMP mechanism I am not aware of, that I should prefer instead.
--Ben.S
The chain_id is the ascii value for the letter stored in the PDB file. I think the main reason for directly returning an int instead of the char is that 26 is kind of a small limit.
On Mar 22, 2011, at 8:07 AM, Benjamin SCHWARZ wrote:
> Hi list, > > I am wondering what properties are attached to the various levels of a hierarchy and how to retrieve it. > As an example, I would like to know how to get the one-character-code that is attached to a chain. > > I have the feeling, this is not strictly feasible, though it is possible to get it as the last character in the particle name of the chain : > > import IMP > import IMP.atom > > m=IMP.Model() > struct_file_name = "/Users/schwarz/DATA/myPDB/1K8K.pdb" > struct1k8k=IMP.atom.read_pdb(struct_file_name,m) > c0=struct1k8k.get_child(0) > print c0.get_name() > > Will result in 'Chain A' being output. Looking at the other properties stored in my c0 chain, I see that everything seems to be integer, including a "chain" attribute that I try to access through > > chainKey = c0.get_int_attributes()[2] > c0.get_value(chainKey) > > which results in the integer 65 being output... > > My questions now : > 1. Is there a way to get directly the one letter code of a chain ? > 2. If not, is there a guaranty that the letter used in the particle name will always reflect the chain ID, or is there a fixed mapping between the value of the chainKey attribute and the chain one letter code ? > 3. Is there a nicer way to get a keyType for instance from its string ? In my example, I retrieved chainKey as the third element of the integer keys list returned by get_int_attributes(), this is not very satisfying, and I thought of resorting to a function such as : > > def getChainKey( chain ): > for k in chain.get_int_attributes() : > if k.get_string() == 'chain' : > return k > return None > > Still, I wonder if there is an IMP mechanism I am not aware of, that I should prefer instead. > > --Ben.S > _______________________________________________ > IMP-users mailing list > IMP-users@salilab.org > https://salilab.org/mailman/listinfo/imp-users
> The chain_id is the ascii value for the letter stored in the PDB file. I think the main reason for directly returning an int instead of the char is that 26 is kind of a small limit.
Oups, thanks Daniel, I missed that method in the documentation :
c0.get_as_chain().get_id()
does the trick.
I still have a question concerning the nice way for retrieving attribute Keys
>> 3. Is there a nicer way to get a keyType for instance from its string ? In my example, I retrieved chainKey as the third element of the integer keys list returned by get_int_attributes(), this is not very satisfying, and I thought of resorting to a function such as : >> >> def getChainKey( chain ): >> for k in chain.get_int_attributes() : >> if k.get_string() == 'chain' : >> return k >> return None >> >> Still, I wonder if there is an IMP mechanism I am not aware of, that I should prefer instead.
--Ben.S
For getting attribute keys, most decorators have methods to retrieve the keys they use eg Chain::get_id_key(). Some decorators may be missing those, please report ones you encounter which do.
On Mar 22, 2011, at 8:37 AM, Benjamin SCHWARZ wrote:
>> The chain_id is the ascii value for the letter stored in the PDB file. I think the main reason for directly returning an int instead of the char is that 26 is kind of a small limit. > > Oups, thanks Daniel, I missed that method in the documentation : > > c0.get_as_chain().get_id() > > does the trick. > > I still have a question concerning the nice way for retrieving attribute Keys > >>> 3. Is there a nicer way to get a keyType for instance from its string ? In my example, I retrieved chainKey as the third element of the integer keys list returned by get_int_attributes(), this is not very satisfying, and I thought of resorting to a function such as : >>> >>> def getChainKey( chain ): >>> for k in chain.get_int_attributes() : >>> if k.get_string() == 'chain' : >>> return k >>> return None >>> >>> Still, I wonder if there is an IMP mechanism I am not aware of, that I should prefer instead. > > --Ben.S > _______________________________________________ > IMP-users mailing list > IMP-users@salilab.org > https://salilab.org/mailman/listinfo/imp-users
> For getting attribute keys, most decorators have methods to retrieve the keys they use eg Chain::get_id_key(). Great ! many thanks.
> Some decorators may be missing those, please report ones you encounter which do. ack
>>> The chain_id is the ascii value for the letter stored in the PDB file. I think the main reason for directly returning an int instead of the char is that 26 is kind of a small limit. >> >> Oups, thanks Daniel, I missed that method in the documentation : >> >> c0.get_as_chain().get_id() >> >> does the trick. >> >> I still have a question concerning the nice way for retrieving attribute Keys >> >>>> 3. Is there a nicer way to get a keyType for instance from its string ? In my example, I retrieved chainKey as the third element of the integer keys list returned by get_int_attributes(), this is not very satisfying, and I thought of resorting to a function such as : >>>> >>>> def getChainKey( chain ): >>>> for k in chain.get_int_attributes() : >>>> if k.get_string() == 'chain' : >>>> return k >>>> return None >>>> >>>> Still, I wonder if there is an IMP mechanism I am not aware of, that I should prefer instead. >> >> --Ben.S
On 3/22/11 8:07 AM, Benjamin SCHWARZ wrote: > I am wondering what properties are attached to the various levels of a > hierarchy and how to retrieve it. > As an example, I would like to know how to get the one-character-code > that is attached to a chain.
Check the documentation: http://salilab.org/imp/nightly/doc/html/classIMP_1_1atom_1_1Chain.html
There should never be a need to mess with keys and attributes in the way you're proposing - the decorators should always provide suitable methods.
> I have the feeling, this is not strictly feasible, though it is possible > to get it as the last character in the particle name of the chain :
The particle name is a tag for the benefit of you, the human. There is no guarantee that it ends in the chain ID, since you can set it to anything you want.
Ben
participants (3)
-
Ben Webb
-
Benjamin SCHWARZ
-
Daniel Russel