No chains in AtomicStructure

Hi, I have created a python plugin that uses AtomicStructure() class to create a model based on the pdb file and custom trajectory file. The problem is that after creating the structure (adding residues and atoms) it has no chains. Due to this issue, I cannot use some of the ChimeraX features (e.g. rainbow coloring) - at least I think this is the reason. While adding new residues one has to specify the chain_id, but even if I do it those chains are not created automatically. Do I have to create chains separately or there is something that I am missing here. Would be grateful for your help. Best, Dominik

Hi Dominik, You should not have to explicitly create Chains, though it's hard to say what's going wrong without seeing the code. Is there a GitHub repository? Anyway here's a few ideas... You don't say explicitly that you create bonds, though I suspect that was just an oversight. Bonds are necessary for finding chain connectivity. Does structure.bonded_groups() return the number of groups of connected atoms that you would expect given the structure you've built? Does structure.polymers() return the number of polymers expected? Residues have to be in chain order, so if you are not creating them in that order you will either have to use the insert/precedes keyword of new_residue() to get them into the correct position, or use structure.reorder_residues() to put them in the right order afterward. --Eric Eric Pettersen UCSF Computer Graphics Lab
On Jun 9, 2023, at 3:02 AM, Dominik Sordyl via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:
Hi,
I have created a python plugin that uses AtomicStructure() class to create a model based on the pdb file and custom trajectory file. The problem is that after creating the structure (adding residues and atoms) it has no chains. Due to this issue, I cannot use some of the ChimeraX features (e.g. rainbow coloring) - at least I think this is the reason. While adding new residues one has to specify the chain_id, but even if I do it those chains are not created automatically. Do I have to create chains separately or there is something that I am missing here. Would be grateful for your help.
Best, Dominik
_______________________________________________ ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu <mailto:chimerax-users@cgl.ucsf.edu> To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu <mailto:chimerax-users-leave@cgl.ucsf.edu> Manage subscription:

Hi Eric, Thanks, for your advices. Yes, I have created bonds between atoms. But one thing that I did not mention was that it is a coarse-grained representation containing only some heavy atoms of each residue. I think I am putting the residues in the right order. Unfortunately I still cannot get chains. structure.polymers() returns an empty list. structure.bonded_group() returns a list of all atoms in the structure I don't know if I can show you the whole code but this is the part I am using for creating a structure: s = AtomicStructure(session, name=file_name, auto_style=True) from chimerax.atomic.struct_edit import add_atom from chimerax.atomic.struct_edit import add_bond last_residue_id = 0 for i, v in enumerate(res_atom_set): coord_id = 0 for x in range(len(v)): atom_num = list(v.values())[x] #number of atoms in each residue new_r = s.new_residue(pdb_residues[last_residue_id], chains[last_residue_id], x) #adds new residue - of name pdb_residues[x], as a part of chain chain[chain_id], position x in chain last_residue_id += 1 for _ in range(atom_num): # iterate the 'number of atoms in residue' times add_atom(pdb_atoms.pop(0), pdb_elements.pop(0), new_r, np.array(coords[0][coord_id])) #adds atoms to the residues coord_id += 1 #Create bonds if "LIGAND" in molecule_type_lookup_dict.values(): for x in pdb.pdb_connect: s.new_bond(s.atoms[x[0]], s.atoms[x[1]]) else: for x in bonds: s.new_bond(s.atoms[x[0]], s.atoms[x[1]]) s.add_coordsets(np.array(coords), replace=True) coordset_slider(session, [s], pause_frames=speed) return [s], "" "res_atom_set" is a dictionary {residue_id: num of atoms} "pdb_residues" is a list with residues' names - earlier obtained from pdb "chains" is a list of length of number of residues, which contains chain for every residue "[A, A, A, A, B, B, B, B]" Most of the features work - it is displayed correctly, the trajectory can be "played" and so on. But actually just now I noticed that when I print(len(s.chains)) it return 0, but color bychain works fine somehow. And if this coloring option works, then why rainbow is not? Best, Dominik ________________________________ From: Eric Pettersen <pett@cgl.ucsf.edu> Sent: Friday, June 9, 2023 9:08 PM To: ChimeraX Users Help <chimerax-users@cgl.ucsf.edu> Cc: Dominik Sordyl <dsordyl@iimcb.gov.pl> Subject: Re: [chimerax-users] No chains in AtomicStructure On Jun 9, 2023, at 12:01 PM, Eric Pettersen via ChimeraX-users <chimerax-users@cgl.ucsf.edu<mailto:chimerax-users@cgl.ucsf.edu>> wrote: use the insert/precedes keyword Should just be the "precedes" keyword. "Insert" is for specifying an insertion code. --Eric

Hi Dominik, If some of the “bonds” in your structure are not in fact covalent bonds but instead represent the fact that those atoms “connect” through other atoms/bonds that are missing, then you need to use a “missing structure” pseudobond to represent that rather than a normal covalent bond. Try this: don’t add any bonds to the structure yourself, but after you’ve created all the atoms and residues, call structure.connect_structure(). Are there any polymers/chains after you do that? Color by chain probably works because it uses chain IDs, whereas rainbow fails because it iterates through the residues of chains. —Eric
On Jun 12, 2023, at 3:15 AM, Dominik Sordyl via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:
Hi Eric, Thanks, for your advices. Yes, I have created bonds between atoms. But one thing that I did not mention was that it is a coarse-grained representation containing only some heavy atoms of each residue. I think I am putting the residues in the right order. Unfortunately I still cannot get chains. structure.polymers() returns an empty list. structure.bonded_group() returns a list of all atoms in the structure
I don't know if I can show you the whole code but this is the part I am using for creating a structure: s = AtomicStructure(session, name=file_name, auto_style=True) from chimerax.atomic.struct_edit import add_atom from chimerax.atomic.struct_edit import add_bond last_residue_id = 0
for i, v in enumerate(res_atom_set): coord_id = 0 for x in range(len(v)): atom_num = list(v.values())[x] #number of atoms in each residue new_r = s.new_residue(pdb_residues[last_residue_id],chains[last_residue_id], x) #adds new residue - of name pdb_residues[x], as a part of chain chain[chain_id], position x in chain last_residue_id += 1 for _ in range(atom_num): # iterate the 'number of atoms in residue' times add_atom(pdb_atoms.pop(0), pdb_elements.pop(0), new_r,np.array(coords[0][coord_id])) #adds atoms to the residues coord_id += 1
#Create bonds if "LIGAND" in molecule_type_lookup_dict.values(): for x in pdb.pdb_connect: s.new_bond(s.atoms[x[0]], s.atoms[x[1]]) else: for x in bonds: s.new_bond(s.atoms[x[0]], s.atoms[x[1]])
s.add_coordsets(np.array(coords), replace=True) coordset_slider(session, [s], pause_frames=speed)
return [s], ""
"res_atom_set" is a dictionary {residue_id: num of atoms} "pdb_residues" is a list with residues' names - earlier obtained from pdb "chains" is a list of length of number of residues, which contains chain for every residue "[A, A, A, A, B, B, B, B]"
Most of the features work - it is displayed correctly, the trajectory can be "played" and so on. But actually just now I noticed that when I print(len(s.chains)) it return 0, but color bychain works fine somehow. And if this coloring option works, then why rainbow is not?
Best, Dominik From: Eric Pettersen <pett@cgl.ucsf.edu <mailto:pett@cgl.ucsf.edu>> Sent: Friday, June 9, 2023 9:08 PM To: ChimeraX Users Help <chimerax-users@cgl.ucsf.edu <mailto:chimerax-users@cgl.ucsf.edu>> Cc: Dominik Sordyl <dsordyl@iimcb.gov.pl <mailto:dsordyl@iimcb.gov.pl>> Subject: Re: [chimerax-users] No chains in AtomicStructure
On Jun 9, 2023, at 12:01 PM, Eric Pettersen via ChimeraX-users <chimerax-users@cgl.ucsf.edu <mailto:chimerax-users@cgl.ucsf.edu>> wrote:
use the insert/precedes keyword
Should just be the "precedes" keyword. "Insert" is for specifying an insertion code.
--Eric _______________________________________________ ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu <mailto:chimerax-users@cgl.ucsf.edu> To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu <mailto:chimerax-users-leave@cgl.ucsf.edu> Manage subscription:

Hi Eric, Thanks a lot for your help. connect_structure() worked. It produced some mess in the bonds but after calling it, deleting bonds created by it and later creating my bonds, it worked. Wish you all the best, Dominik ________________________________ From: Eric Pettersen <pett@cgl.ucsf.edu> Sent: Monday, June 12, 2023 11:59 PM To: Dominik Sordyl <dsordyl@iimcb.gov.pl> Cc: ChimeraX Users Help <chimerax-users@cgl.ucsf.edu> Subject: Re: [chimerax-users] No chains in AtomicStructure Hi Dominik, If some of the “bonds” in your structure are not in fact covalent bonds but instead represent the fact that those atoms “connect” through other atoms/bonds that are missing, then you need to use a “missing structure” pseudobond to represent that rather than a normal covalent bond. Try this: don’t add any bonds to the structure yourself, but after you’ve created all the atoms and residues, call structure.connect_structure(). Are there any polymers/chains after you do that? Color by chain probably works because it uses chain IDs, whereas rainbow fails because it iterates through the residues of chains. —Eric On Jun 12, 2023, at 3:15 AM, Dominik Sordyl via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote: Hi Eric, Thanks, for your advices. Yes, I have created bonds between atoms. But one thing that I did not mention was that it is a coarse-grained representation containing only some heavy atoms of each residue. I think I am putting the residues in the right order. Unfortunately I still cannot get chains. structure.polymers() returns an empty list. structure.bonded_group() returns a list of all atoms in the structure I don't know if I can show you the whole code but this is the part I am using for creating a structure: s = AtomicStructure(session, name=file_name, auto_style=True) from chimerax.atomic.struct_edit import add_atom from chimerax.atomic.struct_edit import add_bond last_residue_id = 0 for i, v in enumerate(res_atom_set): coord_id = 0 for x in range(len(v)): atom_num = list(v.values())[x] #number of atoms in each residue new_r = s.new_residue(pdb_residues[last_residue_id],chains[last_residue_id], x) #adds new residue - of name pdb_residues[x], as a part of chain chain[chain_id], position x in chain last_residue_id += 1 for _ in range(atom_num): # iterate the 'number of atoms in residue' times add_atom(pdb_atoms.pop(0), pdb_elements.pop(0), new_r,np.array(coords[0][coord_id])) #adds atoms to the residues coord_id += 1 #Create bonds if "LIGAND" in molecule_type_lookup_dict.values(): for x in pdb.pdb_connect: s.new_bond(s.atoms[x[0]], s.atoms[x[1]]) else: for x in bonds: s.new_bond(s.atoms[x[0]], s.atoms[x[1]]) s.add_coordsets(np.array(coords), replace=True) coordset_slider(session, [s], pause_frames=speed) return [s], "" "res_atom_set" is a dictionary {residue_id: num of atoms} "pdb_residues" is a list with residues' names - earlier obtained from pdb "chains" is a list of length of number of residues, which contains chain for every residue "[A, A, A, A, B, B, B, B]" Most of the features work - it is displayed correctly, the trajectory can be "played" and so on. But actually just now I noticed that when I print(len(s.chains)) it return 0, but color bychain works fine somehow. And if this coloring option works, then why rainbow is not? Best, Dominik ________________________________ From: Eric Pettersen <pett@cgl.ucsf.edu<mailto:pett@cgl.ucsf.edu>> Sent: Friday, June 9, 2023 9:08 PM To: ChimeraX Users Help <chimerax-users@cgl.ucsf.edu<mailto:chimerax-users@cgl.ucsf.edu>> Cc: Dominik Sordyl <dsordyl@iimcb.gov.pl<mailto:dsordyl@iimcb.gov.pl>> Subject: Re: [chimerax-users] No chains in AtomicStructure On Jun 9, 2023, at 12:01 PM, Eric Pettersen via ChimeraX-users <chimerax-users@cgl.ucsf.edu<mailto:chimerax-users@cgl.ucsf.edu>> wrote: use the insert/precedes keyword Should just be the "precedes" keyword. "Insert" is for specifying an insertion code. --Eric _______________________________________________ ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu<mailto:chimerax-users@cgl.ucsf.edu> To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu<mailto:chimerax-users-leave@cgl.ucsf.edu> Manage subscription:

Hi Dominik, Glad you got things working. If you know which "bonds" actually should be missing-structure pseudobonds, you can sidestep connect_structure() and create them yourself with: pbg = structure.pseudobond_group(structure.PBG_MISSING_STRUCTURE) pbg.new_pseudobond(atom1, atom2) --Eric
On Jun 13, 2023, at 1:07 AM, Dominik Sordyl via ChimeraX-users <chimerax-users@cgl.ucsf.edu> wrote:
Hi Eric, Thanks a lot for your help. connect_structure() worked. It produced some mess in the bonds but after calling it, deleting bonds created by it and later creating my bonds, it worked.
Wish you all the best, Dominik From: Eric Pettersen <pett@cgl.ucsf.edu <mailto:pett@cgl.ucsf.edu>> Sent: Monday, June 12, 2023 11:59 PM To: Dominik Sordyl <dsordyl@iimcb.gov.pl <mailto:dsordyl@iimcb.gov.pl>> Cc: ChimeraX Users Help <chimerax-users@cgl.ucsf.edu <mailto:chimerax-users@cgl.ucsf.edu>> Subject: Re: [chimerax-users] No chains in AtomicStructure
Hi Dominik, If some of the “bonds” in your structure are not in fact covalent bonds but instead represent the fact that those atoms “connect” through other atoms/bonds that are missing, then you need to use a “missing structure” pseudobond to represent that rather than a normal covalent bond. Try this: don’t add any bonds to the structure yourself, but after you’ve created all the atoms and residues, call structure.connect_structure(). Are there any polymers/chains after you do that? Color by chain probably works because it uses chain IDs, whereas rainbow fails because it iterates through the residues of chains.
—Eric
On Jun 12, 2023, at 3:15 AM, Dominik Sordyl via ChimeraX-users <chimerax-users@cgl.ucsf.edu <mailto:chimerax-users@cgl.ucsf.edu>> wrote:
Hi Eric, Thanks, for your advices. Yes, I have created bonds between atoms. But one thing that I did not mention was that it is a coarse-grained representation containing only some heavy atoms of each residue. I think I am putting the residues in the right order. Unfortunately I still cannot get chains. structure.polymers() returns an empty list. structure.bonded_group() returns a list of all atoms in the structure
I don't know if I can show you the whole code but this is the part I am using for creating a structure: s = AtomicStructure(session, name=file_name, auto_style=True) from chimerax.atomic.struct_edit import add_atom from chimerax.atomic.struct_edit import add_bond last_residue_id = 0
for i, v in enumerate(res_atom_set): coord_id = 0 for x in range(len(v)): atom_num = list(v.values())[x] #number of atoms in each residue new_r = s.new_residue(pdb_residues[last_residue_id],chains[last_residue_id], x) #adds new residue - of name pdb_residues[x], as a part of chain chain[chain_id], position x in chain last_residue_id += 1 for _ in range(atom_num): # iterate the 'number of atoms in residue' times add_atom(pdb_atoms.pop(0), pdb_elements.pop(0), new_r,np.array(coords[0][coord_id])) #adds atoms to the residues coord_id += 1
#Create bonds if "LIGAND" in molecule_type_lookup_dict.values(): for x in pdb.pdb_connect: s.new_bond(s.atoms[x[0]], s.atoms[x[1]]) else: for x in bonds: s.new_bond(s.atoms[x[0]], s.atoms[x[1]])
s.add_coordsets(np.array(coords), replace=True) coordset_slider(session, [s], pause_frames=speed)
return [s], ""
"res_atom_set" is a dictionary {residue_id: num of atoms} "pdb_residues" is a list with residues' names - earlier obtained from pdb "chains" is a list of length of number of residues, which contains chain for every residue "[A, A, A, A, B, B, B, B]"
Most of the features work - it is displayed correctly, the trajectory can be "played" and so on. But actually just now I noticed that when I print(len(s.chains)) it return 0, but color bychain works fine somehow. And if this coloring option works, then why rainbow is not?
Best, Dominik From: Eric Pettersen <pett@cgl.ucsf.edu <mailto:pett@cgl.ucsf.edu>> Sent: Friday, June 9, 2023 9:08 PM To: ChimeraX Users Help <chimerax-users@cgl.ucsf.edu <mailto:chimerax-users@cgl.ucsf.edu>> Cc: Dominik Sordyl <dsordyl@iimcb.gov.pl <mailto:dsordyl@iimcb.gov.pl>> Subject: Re: [chimerax-users] No chains in AtomicStructure
On Jun 9, 2023, at 12:01 PM, Eric Pettersen via ChimeraX-users <chimerax-users@cgl.ucsf.edu <mailto:chimerax-users@cgl.ucsf.edu>> wrote:
use the insert/precedes keyword
Should just be the "precedes" keyword. "Insert" is for specifying an insertion code.
--Eric _______________________________________________ ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu <mailto:chimerax-users@cgl.ucsf.edu> To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu <mailto:chimerax-users-leave@cgl.ucsf.edu> Manage subscription:
_______________________________________________ ChimeraX-users mailing list -- chimerax-users@cgl.ucsf.edu <mailto:chimerax-users@cgl.ucsf.edu> To unsubscribe send an email to chimerax-users-leave@cgl.ucsf.edu <mailto:chimerax-users-leave@cgl.ucsf.edu> Manage subscription:
participants (2)
-
Dominik Sordyl
-
Eric Pettersen