<p>Your method doesn't work for two possible reasons;</p>
<ol>
<li>The radius information may be incorrect.</li>
<li>Your molecule requires some minimization. This option helps to optimize distance between atoms.</li>
</ol>
<p>You can find some information about the minimization at the following links</p>
<ol>
<li><a href="https://en.wikipedia.org/wiki/Energy_minimization" rel="nofollow noreferrer">Wikipedia</a></li>
<li><a href="https://manual.gromacs.org/documentation/current/reference-manual/algorithms/energy-minimization.html" rel="nofollow noreferrer">Gromacs</a></li>
</ol>

CC BY-SA 4.0
2022-11-24T23:29:11.930Z
2022-11-24T23:29:11.930Z
SuleymanSelim
<p>Let us consider the first seven atoms of the  protein <strong><code>1CRN.pdb</code></strong>:</p>
<pre><code>ATOM      1  N   THR A   1      17.047  14.099   3.625  1.00 13.79           N  
ATOM      2  CA  THR A   1      16.967  12.784   4.338  1.00 10.80           C  
ATOM      3  C   THR A   1      15.685  12.755   5.133  1.00  9.19           C  
ATOM      4  O   THR A   1      15.268  13.825   5.594  1.00  9.85           O  
ATOM      5  CB  THR A   1      18.170  12.703   5.337  1.00 13.02           C  
ATOM      6  OG1 THR A   1      19.334  12.829   4.463  1.00 15.06           O  
ATOM      7  CG2 THR A   1      18.150  11.546   6.304  1.00 14.23           C  
</code></pre>
<p>This represents an amino acid called <em><strong>Threonine</strong></em>.</p>
<p>The general bond diagram for Threonine is as follows:</p>
<p><a href="https://i.sstatic.net/etZHI.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/etZHI.png" alt="enter image description here" /></a></p>
<p>So, it has at least six bonds (I am actually not sure!) which are also evident from the seven <code>ATOM</code> lines.</p>
<p>Each atom has its radius. In general, if the distance between two atoms is less than the sum of the radii, there is a bond between these two atoms.</p>
<p>Based on the above information, I tried to identify the bond information, and I could detect only two:</p>
<pre><code>     atom1           atom2        distance       atm1 Radi      atom2 Radi        sum radi        is bond?
         N              CA            1.50            0.65            0.70            1.35           False
         N               C            2.44            0.65            0.70            1.35           False
         N               O            2.67            0.65            0.60            1.25           False
         N              CB            2.48            0.65            0.70            1.35           False
         N             OG1            2.75            0.65            0.60            1.25           False
         N             CG2            3.86            0.65            0.60            1.25           False
        CA               N            1.50            0.70            0.65            1.35           False
        CA               C            1.51            0.70            0.70            1.40           False
        CA               O            2.36            0.70            0.60            1.30           False
        CA              CB            1.57            0.70            0.70            1.40           False
        CA             OG1            2.37            0.70            0.60            1.30           False
        CA             CG2            2.61            0.70            0.60            1.30           False
         C               N            2.44            0.70            0.65            1.35           False
         C              CA            1.51            0.70            0.70            1.40           False
         C               O            1.24            0.70            0.60            1.30            True
         C              CB            2.49            0.70            0.70            1.40           False
         C             OG1            3.71            0.70            0.60            1.30           False
         C             CG2            2.98            0.70            0.60            1.30           False
         O               N            2.67            0.60            0.65            1.25           False
         O              CA            2.36            0.60            0.70            1.30           False
         O               C            1.24            0.60            0.70            1.30            True
         O              CB            3.12            0.60            0.70            1.30           False
         O             OG1            4.34            0.60            0.60            1.20           False
         O             CG2            3.74            0.60            0.60            1.20           False
        CB               N            2.48            0.70            0.65            1.35           False
        CB              CA            1.57            0.70            0.70            1.40           False
        CB               C            2.49            0.70            0.70            1.40           False
        CB               O            3.12            0.70            0.60            1.30           False
        CB             OG1            1.46            0.70            0.60            1.30           False
        CB             CG2            1.51            0.70            0.60            1.30           False
       OG1               N            2.75            0.60            0.65            1.25           False
       OG1              CA            2.37            0.60            0.70            1.30           False
       OG1               C            3.71            0.60            0.70            1.30           False
       OG1               O            4.34            0.60            0.60            1.20           False
       OG1              CB            1.46            0.60            0.70            1.30           False
       OG1             CG2            2.54            0.60            0.60            1.20           False
       CG2               N            3.86            0.60            0.65            1.25           False
       CG2              CA            2.61            0.60            0.70            1.30           False
       CG2               C            2.98            0.60            0.70            1.30           False
       CG2               O            3.74            0.60            0.60            1.20           False
       CG2              CB            1.51            0.60            0.70            1.30           False
       CG2             OG1            2.54            0.60            0.60            1.20           False
2
Done!
</code></pre>
<p>How can I detect all bonds?</p>
<p>EDIT: As per pippo1980's request:</p>

<pre class="lang-csharp prettyprint-override"><code>public class ADTResidue: Dictionary&lt;int, ADTAtom&gt;, IEquatable&lt;ADTResidue&gt;
{
    public string ProteinName { get; set; }
    public string ChainName { get; set; }
    public int ResidueNo { get; set; }
    public Point3d Coordinate { get; private set; }
    public string Code { get; set; }
    public string Full { get; set; }
    public Color ColorRGB { get; set; }

    
    public ADTResidue(string code, string full, Color colorRgb)
    {
        Coordinate = new Point3d();

        Code = code;
        Full = full;
        ColorRGB = colorRgb;
    }

    private readonly Dictionary&lt;int, CovalentBond&gt; BondDictionary;

    public List&lt;CovalentBond&gt; GetBonds()
    {
        return new List&lt;CovalentBond&gt;(BondDictionary.Values);
    }

    public ADTResidue()
    {
        BondDictionary = new Dictionary&lt;int, CovalentBond&gt;();
    }

    public void CalculateBonds()
    {
        foreach (ADTAtom atom1 in this.Values)
        {
            foreach (ADTAtom atom2 in this.Values)
            {
                if (atom2.Radius &lt;= 0)
                {
                    throw new Exception(&quot;zero radius in &quot; + atom2.Name);
                }

                if (atom1 != atom2)
                {
                    double distance = Point3d.Distance(atom1.Coordinate, atom2.Coordinate);

                    bool exists = ABond.IsBondExists(atom1.Coordinate, atom2.Coordinate, atom1.Radius, atom2.Radius);

                    if (exists)
                    {
                        int hashCode = atom1.GetHashCode(atom2);
                        if (!BondDictionary.ContainsKey(hashCode))
                        {
                            BondDictionary.Add(hashCode, new CovalentBond(atom1, atom2));
                        }
                    }
                }
            }
        }

        int count = BondDictionary.Count;

        Console.WriteLine(count);
    }

    #region equality comparison
    // IEquatable&lt;&gt; implementation...
    #endregion
} 

public abstract class ABond: Pair&lt;ADTAtom, ADTAtom&gt;
{
    public ABond():base()
    {
    }

    public ABond(ADTAtom first, ADTAtom second) : base(first, second)
    {
    }

    public static bool IsBondExists(Point3d first, Point3d second, double radius1, double radius2)
    {
        double distance = Point3d.Distance(first, second);

        return (distance &lt;= (radius1 + radius2));
    }
}

public class CovalentBond : ABond
{
    public CovalentBond():base()
    {
    }

    public CovalentBond(ADTAtom first, ADTAtom second) : base(first, second)
    {
    }
}
</code></pre>


CC BY-SA 4.0
2022-11-26T17:55:50.653Z
would you share your code with us ?
pippo1980
CC BY-SA 4.0
2022-11-26T18:11:20.290Z
@pippo1980, its a part of a bigger framework. I am sharing a smaller part of it. Hope that helps.
user366312
CC BY-SA 4.0
2022-11-26T18:18:39.090Z
unfortunately not, but could help others. Did you try running it on first T of 3NIR.pdb ?
pippo1980
CC BY-SA 4.0
2022-11-26T18:21:09.630Z
@pippo1980, Yes. My code works now. Previously, I made mistakes with radii values.
user366312
CC BY-SA 4.0
2022-11-26T18:32:43.657Z
is that above C#    ?
pippo1980
CC BY-SA 4.0
2022-11-26T18:34:03.587Z
@pippo1980, Yes.
user366312
CC BY-SA 4.0
2022-11-26T18:34:34.733Z
is it same as java ?
pippo1980
CC BY-SA 4.0
2022-11-26T18:38:24.770Z
@pippo1980, Not same, but similar.
user366312
<proteins><protein-structure><pdb><3d-structure>
Why am I not being able to detect all the bonds in a residue?
# Why am I not being able to detect all the bonds in a residue?

(Asked by: username_0 on 2022-11-24)

Let us consider the first seven atoms of the  protein 1CRN.pdb:
ATOM      1  N   THR A   1      17.047  14.099   3.625  1.00 13.79           N  
ATOM      2  CA  THR A   1      16.967  12.784   4.338  1.00 10.80           C  
ATOM      3  C   THR A   1      15.685  12.755   5.133  1.00  9.19           C  
ATOM      4  O   THR A   1      15.268  13.825   5.594  1.00  9.85           O  
ATOM      5  CB  THR A   1      18.170  12.703   5.337  1.00 13.02           C  
ATOM      6  OG1 THR A   1      19.334  12.829   4.463  1.00 15.06           O  
ATOM      7  CG2 THR A   1      18.150  11.546   6.304  1.00 14.23           C  

This represents an amino acid called Threonine.
The general bond diagram for Threonine is as follows:

So, it has at least six bonds (I am actually not sure!) which are also evident from the seven ATOM lines.
Each atom has its radius. In general, if the distance between two atoms is less than the sum of the radii, there is a bond between these two atoms.
Based on the above information, I tried to identify the bond information, and I could detect only two:
     atom1           atom2        distance       atm1 Radi      atom2 Radi        sum radi        is bond?
         N              CA            1.50            0.65            0.70            1.35           False
         N               C            2.44            0.65            0.70            1.35           False
         N               O            2.67            0.65            0.60            1.25           False
         N              CB            2.48            0.65            0.70            1.35           False
         N             OG1            2.75            0.65            0.60            1.25           False
         N             CG2            3.86            0.65            0.60            1.25           False
        CA               N            1.50            0.70            0.65            1.35           False
        CA               C            1.51            0.70            0.70            1.40           False
        CA               O            2.36            0.70            0.60            1.30           False
        CA              CB            1.57            0.70            0.70            1.40           False
        CA             OG1            2.37            0.70            0.60            1.30           False
        CA             CG2            2.61            0.70            0.60            1.30           False
         C               N            2.44            0.70            0.65            1.35           False
         C              CA            1.51            0.70            0.70            1.40           False
         C               O            1.24            0.70            0.60            1.30            True
         C              CB            2.49            0.70            0.70            1.40           False
         C             OG1            3.71            0.70            0.60            1.30           False
         C             CG2            2.98            0.70            0.60            1.30           False
         O               N            2.67            0.60            0.65            1.25           False
         O              CA            2.36            0.60            0.70            1.30           False
         O               C            1.24            0.60            0.70            1.30            True
         O              CB            3.12            0.60            0.70            1.30           False
         O             OG1            4.34            0.60            0.60            1.20           False
         O             CG2            3.74            0.60            0.60            1.20           False
        CB               N            2.48            0.70            0.65            1.35           False
        CB              CA            1.57            0.70            0.70            1.40           False
        CB               C            2.49            0.70            0.70            1.40           False
        CB               O            3.12            0.70            0.60            1.30           False
        CB             OG1            1.46            0.70            0.60            1.30           False
        CB             CG2            1.51            0.70            0.60            1.30           False
       OG1               N            2.75            0.60            0.65            1.25           False
       OG1              CA            2.37            0.60            0.70            1.30           False
       OG1               C            3.71            0.60            0.70            1.30           False
       OG1               O            4.34            0.60            0.60            1.20           False
       OG1              CB            1.46            0.60            0.70            1.30           False
       OG1             CG2            2.54            0.60            0.60            1.20           False
       CG2               N            3.86            0.60            0.65            1.25           False
       CG2              CA            2.61            0.60            0.70            1.30           False
       CG2               C            2.98            0.60            0.70            1.30           False
       CG2               O            3.74            0.60            0.60            1.20           False
       CG2              CB            1.51            0.60            0.70            1.30           False
       CG2             OG1            2.54            0.60            0.60            1.20           False
2
Done!

How can I detect all bonds?
EDIT: As per pippo1980's request:
public class ADTResidue: Dictionary, IEquatable
{
    public string ProteinName { get; set; }
    public string ChainName { get; set; }
    public int ResidueNo { get; set; }
    public Point3d Coordinate { get; private set; }
    public string Code { get; set; }
    public string Full { get; set; }
    public Color ColorRGB { get; set; }

    
    public ADTResidue(string code, string full, Color colorRgb)
    {
        Coordinate = new Point3d();

        Code = code;
        Full = full;
        ColorRGB = colorRgb;
    }

    private readonly Dictionary BondDictionary;

    public List GetBonds()
    {
        return new List(BondDictionary.Values);
    }

    public ADTResidue()
    {
        BondDictionary = new Dictionary();
    }

    public void CalculateBonds()
    {
        foreach (ADTAtom atom1 in this.Values)
        {
            foreach (ADTAtom atom2 in this.Values)
            {
                if (atom2.Radius <= 0)
                {
                    throw new Exception("zero radius in " + atom2.Name);
                }

                if (atom1 != atom2)
                {
                    double distance = Point3d.Distance(atom1.Coordinate, atom2.Coordinate);

                    bool exists = ABond.IsBondExists(atom1.Coordinate, atom2.Coordinate, atom1.Radius, atom2.Radius);

                    if (exists)
                    {
                        int hashCode = atom1.GetHashCode(atom2);
                        if (!BondDictionary.ContainsKey(hashCode))
                        {
                            BondDictionary.Add(hashCode, new CovalentBond(atom1, atom2));
                        }
                    }
                }
            }
        }

        int count = BondDictionary.Count;

        Console.WriteLine(count);
    }

    #region equality comparison
    // IEquatable<> implementation...
    #endregion
} 

public abstract class ABond: Pair
{
    public ABond():base()
    {
    }

    public ABond(ADTAtom first, ADTAtom second) : base(first, second)
    {
    }

    public static bool IsBondExists(Point3d first, Point3d second, double radius1, double radius2)
    {
        double distance = Point3d.Distance(first, second);

        return (distance <= (radius1 + radius2));
    }
}

public class CovalentBond : ABond
{
    public CovalentBond():base()
    {
    }

    public CovalentBond(ADTAtom first, ADTAtom second) : base(first, second)
    {
    }
}

**Tags:** proteins, protein-structure, pdb, 3d-structure
> **Comments:**
> **username_1**: would you share your code with us ?  
> **username_0**: @pippo1980, its a part of a bigger framework. I am sharing a smaller part of it. Hope that helps.  
> **username_1**: unfortunately not, but could help others. Did you try running it on first T of 3NIR.pdb ?  
> **username_0**: @pippo1980, Yes. My code works now. Previously, I made mistakes with radii values.  
> **username_1**: is that above C#    ?  
> **username_0**: @pippo1980, Yes.  
> **username_1**: is it same as java ?  
> **username_0**: @pippo1980, Not same, but similar.  

---

## 1 answers

### Answer by username_2 on 2022-11-24. Score: 3 | Accepted answer

Your method doesn't work for two possible reasons;

1. The radius information may be incorrect.
2. Your molecule requires some minimization. This option helps to optimize distance between atoms.

You can find some information about the minimization at the following links

1. [Wikipedia](https://en.wikipedia.org/wiki/Energy_minimization)
2. [Gromacs](https://manual.gromacs.org/documentation/current/reference-manual/algorithms/energy-minimization.html)


---

