<p>It turns out that in order to generate the internal coordinates for a protein structure, one shouldn't manually create an <code>IC_Chain</code> object, but rather just use the <code>atom_to_internal_coordinates()</code> method of the structure and the <code>internal_to_atom_coordinates()</code> one for the inverse functionality.</p>
<pre><code>structure.atom_to_internal_coordinates()

# Now you have access to the bond angles and lengths
# of the first chain of structure as follows:
chain = list(structure.get_chains())[0]
ic_chain = chain.internal_coord

# Dictionary mapping 3 AtomKeys to a Hedron 
# (with len12, len23, angle fields):
# ic_chain.hedra

# Dictionary mapping 4 AtomKeys to a Dihedraon
# (with angle field for torsion angles):
# ic_chain.dihedra

structure.internal_to_atom_coordinates()
</code></pre>

CC BY-SA 4.0
2022-08-23T18:41:01.580Z
Maybe you know the answer to [this related (and bountied) question](https://bioinformatics.stackexchange.com/questions/19570/read-pdb-file-extract-dihedral-angles-modify-dihedral-angles-reconstruct-cart/)?
epsilone
CC BY-SA 4.0
2022-04-06T16:54:14.933Z
2022-04-06T16:54:14.933Z
CubeHead
<p>not able to grasp the question, tried to figure out a way to show the internal_coordinates:</p>
<pre><code>from Bio.PDB import PDBParser, PICIO, PDBIO


# Read PDB entry.
parser = PDBParser(PERMISSIVE=1, QUIET=1)
structure = parser.get_structure('', 'example.pdb')

print(dir(structure)) # 'atom_to_internal_coordinates' and
                      # 'internal_to_atom_coordinates' seems
                      # to be structure methods


# Generate protein internal coordinates (angles).

structure.atom_to_internal_coordinates(verbose = True)

PICIO.write_PIC(structure[0]['A'], 'internal')


# Generate back 3D coordinates from angles.


pippo = PICIO.read_PIC('internal')

pippo.internal_to_atom_coordinates(verbose = True)

print(pippo)


io = PDBIO()

io.set_structure(pippo)

io.save('atom_coord.pdb',  preserve_atom_numbering=True) 

</code></pre>
<p>compare <code>example.pdb</code> to <code>internal</code> and <code>atom_coord.pdb</code>;</p>
<p>have a look at <code>internal</code>  file contents if you comment out</p>
<p><code>structure.atom_to_internal_coordinates(verbose = True)</code> (around line 17 of</p>
<p>code, # Generate protein internal coordinates (angles). block-code )</p>

CC BY-SA 4.0
2022-03-29T21:11:39.903Z
2022-03-29T21:11:39.903Z
pippo1980
<p>I have been successfully using BioPython's functionality for extracting protein torsion angles using the <code>IC_Chain</code> module. However, I am currently looking to use the inverse functionality as follows:</p>
<pre><code>from Bio.PDB import PDBParser, internal_coords

# Read PDB entry.
parser = PDBParser(PERMISSIVE=1, QUIET=1)
structure = parser.get_structure('', 'example.pdb')

# Generate protein internal coordinates (angles).
ic_chain_bound = internal_coords.IC_Chain(structure)
ic_chain_bound.atom_to_internal_coordinates()

# Generate back 3D coordinates from angles.
ic_chain_bound.internal_to_atom_coordinates()
</code></pre>
<p>but this fails with the following error:</p>
<pre><code>Traceback (most recent call last):
  File &quot;test_biopython_internal_coords.py&quot;, line 97, in &lt;module&gt;
    main(args)
  File &quot;test_biopython_internal_coords.py&quot;, line 89, in main
    ic_chain_bound.internal_to_atom_coordinates()
  File &quot;/software/anaconda/installation/envs/alphafold/lib/python3.7/site-packages/Bio/PDB/internal_coords.py&quot;, line 661, in internal_to_atom_coordinates
    verbose=verbose, start=start, fin=fin
  File &quot;software/anaconda/installation/envs/alphafold/lib/python3.7/site-packages/Bio/PDB/internal_coords.py&quot;, line 415, in assemble_residues
    Dict[AtomKey, numpy.array], ric.assemble(verbose=verbose)
  File &quot;/software/anaconda/installation/envs/alphafold/lib/python3.7/site-packages/Bio/PDB/internal_coords.py&quot;, line 1732, in assemble
    atomCoords = self.get_startpos()
  File &quot;/software/anaconda/installation/envs/alphafold/lib/python3.7/site-packages/Bio/PDB/internal_coords.py&quot;, line 1632, in get_startpos
    sp = self.residue.parent.internal_coord.initNCaC.get(self.rbase, None)
AttributeError: 'NoneType' object has no attribute 'initNCaC'
</code></pre>
<p>Is this not the intended use? Could someone help me figure out why this is failing?</p>
<p>I'm using <a href="https://pastebin.com/m3P8f8rM" rel="nofollow noreferrer">this PDB file</a> in my example, but the code previously failed for all other PDB files I tried.</p>
<p>Thanks!</p>

CC BY-SA 4.0
2022-03-29T16:48:32.627Z
Your `ic_chain_bound.residue.parent.internal_coord` is None... So your `ic_chain_bound.residue.parent` needs to be given coordinates... `help` and `dir` on it may help
Matteo Ferla
CC BY-SA 4.0
2022-03-29T18:08:24.083Z
@MatteoFerla set_residues() ---> set_residue() ??? or something else ? trying to figure out from https://biopython.org/docs/latest/api/Bio.PDB.internal_coords.html but I am lost
pippo1980
CC BY-SA 4.0
2022-03-29T18:10:56.483Z
here https://biopython.org/docs/dev/api/Bio.PDB.internal_coords.html seems better
pippo1980
<python><proteins><protein-structure><biopython>
Help using BioPython's IC_Chain functionality for getting protein 3D coordinates from torsion angles
# Help using BioPython's IC_Chain functionality for getting protein 3D coordinates from torsion angles

(Asked by: username_0 on 2022-03-29)

I have been successfully using BioPython's functionality for extracting protein torsion angles using the IC_Chain module. However, I am currently looking to use the inverse functionality as follows:
from Bio.PDB import PDBParser, internal_coords

# Read PDB entry.
parser = PDBParser(PERMISSIVE=1, QUIET=1)
structure = parser.get_structure('', 'example.pdb')

# Generate protein internal coordinates (angles).
ic_chain_bound = internal_coords.IC_Chain(structure)
ic_chain_bound.atom_to_internal_coordinates()

# Generate back 3D coordinates from angles.
ic_chain_bound.internal_to_atom_coordinates()

but this fails with the following error:
Traceback (most recent call last):
  File "test_biopython_internal_coords.py", line 97, in 
    main(args)
  File "test_biopython_internal_coords.py", line 89, in main
    ic_chain_bound.internal_to_atom_coordinates()
  File "/software/anaconda/installation/envs/alphafold/lib/python3.7/site-packages/Bio/PDB/internal_coords.py", line 661, in internal_to_atom_coordinates
    verbose=verbose, start=start, fin=fin
  File "software/anaconda/installation/envs/alphafold/lib/python3.7/site-packages/Bio/PDB/internal_coords.py", line 415, in assemble_residues
    Dict[AtomKey, numpy.array], ric.assemble(verbose=verbose)
  File "/software/anaconda/installation/envs/alphafold/lib/python3.7/site-packages/Bio/PDB/internal_coords.py", line 1732, in assemble
    atomCoords = self.get_startpos()
  File "/software/anaconda/installation/envs/alphafold/lib/python3.7/site-packages/Bio/PDB/internal_coords.py", line 1632, in get_startpos
    sp = self.residue.parent.internal_coord.initNCaC.get(self.rbase, None)
AttributeError: 'NoneType' object has no attribute 'initNCaC'

Is this not the intended use? Could someone help me figure out why this is failing?
I'm using this PDB file in my example, but the code previously failed for all other PDB files I tried.
Thanks!

**Tags:** python, proteins, protein-structure, biopython
> **Comments:**
> **username_1**: Your `ic_chain_bound.residue.parent.internal_coord` is None... So your `ic_chain_bound.residue.parent` needs to be given coordinates... `help` and `dir` on it may help  
> **username_2**: @MatteoFerla set_residues() ---> set_residue() ??? or something else ? trying to figure out from https://biopython.org/docs/latest/api/Bio.PDB.internal_coords.html but I am lost  
> **username_2**: here https://biopython.org/docs/dev/api/Bio.PDB.internal_coords.html seems better  

---

## 2 answers

### Answer by username_0 on 2022-04-06. Score: 2 | Accepted answer

It turns out that in order to generate the internal coordinates for a protein structure, one shouldn't manually create an IC_Chain object, but rather just use the atom_to_internal_coordinates() method of the structure and the internal_to_atom_coordinates() one for the inverse functionality.
structure.atom_to_internal_coordinates()

# Now you have access to the bond angles and lengths
# of the first chain of structure as follows:
chain = list(structure.get_chains())[0]
ic_chain = chain.internal_coord

# Dictionary mapping 3 AtomKeys to a Hedron 
# (with len12, len23, angle fields):
# ic_chain.hedra

# Dictionary mapping 4 AtomKeys to a Dihedraon
# (with angle field for torsion angles):
# ic_chain.dihedra

structure.internal_to_atom_coordinates()

> **Comments:**
> **username_3**: Maybe you know the answer to [this related (and bountied) question](https://bioinformatics.stackexchange.com/questions/19570/read-pdb-file-extract-dihedral-angles-modify-dihedral-angles-reconstruct-cart/)?  

---

### Answer by username_2 on 2022-03-29. Score: 2

not able to grasp the question, tried to figure out a way to show the internal_coordinates:
from Bio.PDB import PDBParser, PICIO, PDBIO


# Read PDB entry.
parser = PDBParser(PERMISSIVE=1, QUIET=1)
structure = parser.get_structure('', 'example.pdb')

print(dir(structure)) # 'atom_to_internal_coordinates' and
                      # 'internal_to_atom_coordinates' seems
                      # to be structure methods


# Generate protein internal coordinates (angles).

structure.atom_to_internal_coordinates(verbose = True)

PICIO.write_PIC(structure[0]['A'], 'internal')


# Generate back 3D coordinates from angles.


pippo = PICIO.read_PIC('internal')

pippo.internal_to_atom_coordinates(verbose = True)

print(pippo)


io = PDBIO()

io.set_structure(pippo)

io.save('atom_coord.pdb',  preserve_atom_numbering=True) 


compare example.pdb to internal and atom_coord.pdb;
have a look at internal  file contents if you comment out
structure.atom_to_internal_coordinates(verbose = True) (around line 17 of
code, # Generate protein internal coordinates (angles). block-code )


---

