2
$\begingroup$

Just starting out in Blender, but have a reasonable background in programming. I want to import a crystal structure into Blender (v2.82), and I've been using a couple programs to generate PDB (Protein Database) files.

PDB Import Error

I'm having trouble importing a specific file [Crystal1.pdb] at the moment that has a desirable minimal structure. On import I get the following error (snapshot here as well):

Traceback (most recent call last):
File "D:\Program Files\Blender Foundation\Blender 2.82\2.82\scripts\addons\io_mesh_atomic\pdb_gui.py", line 232, in execute
  filepath_pdb)
File "D:\Program Files\Blender Foundation\Blender 2.82\2.82\scripts\addons\io_mesh_atomic\pdb_import.py", line 1503, in import_pdb
  list_coll_elements)
File "D:\Program Files\Blender Foundation\Blender 2.82\2.82\scripts\addons\io_mesh_atomic\pdb_import.py", line 872, in draw_sticks_dupliverts
  n_b   = b / b.length
ZeroDivisionError: Vector division: divide by zero error

location: <unknown location>:-1

I've figured out what the code is doing, drawing the sticks between atoms.

There are a few symmetries in the crystal I'm using (see additional information) that imply some atoms are reflected about the origin (i.e. Atom 2 and 13 of Crystal1.pdb). I think that having two atoms connected with opposite vector coordinates causes the error (see below section). This view is supported by the observation that when I shift the displacement of the crystal generation, the error doesn't seem to occur (crystal 2).

One issue with this idea is that there shouldn't really be any direct bonds / connections between reflected atoms. This has left me rather confused.

Questions

So.....

  • What's the real reason I can't import this file?
  • Does it have anything to do with being reflected around an origin / connected? Or is my PDB file incorrect?
  • What is the pdb_import actually doing here? I'm not really sure to be honest (all the vector stuff below). I don't have a great understanding of the back-end of Blender.

Additional info:

Digging into the math of pdb_import.py

pdb_import.py : draw_sticks_dupliverts

...
for stick in stick_list:
        dv = stick[2]
        v1 = stick[1]
        n  = dv / dv.length
        gamma = -n.dot(v1)
        b     = v1 + gamma * n
        n_b   = b / b.length

If I follow this correctly:

  • n is the unit vector in the direction from v1 to v2.

    \begin{align}n = \frac{v_2-v_1}{\left|v_2-v_1\right|}, dv=v_2-v_1 \end{align}

  • gamma is the negative of the dot product of the unit vector n with v1 itself. This is the projection of v1 along the direction n.

    \begin{align}gamma=-n\cdot v_1 = -\frac{v_2-v_1}{\left|v_2-v_1\right|}\cdot v_1 = -(v_2-v_1)\cdot v_1 \times \frac{1}{\left|v_2-v_1\right|}\end{align}

    Normally you see this as $A\cdot B = \left|A\right|\left|B\right|cos(\theta)$, where $\theta$ is the angle between the two vectors, though $\left|n\right|=1$.

  • b is the vector addition, of the first vertex v1 and the projection along the unit vector, calculated by multiplying the magnitude gamma with n.

    \begin{align} b = v_1 + n*gamma = v_1 - \frac{1}{\left|v_2-v_1\right|} (v_2-v_1)\cdot v_1 \times \frac{1}{\left|v_2-v_1\right|} \end{align}

    Resulting with

\begin{align} b= v_1 + \frac{-1}{\left|v_2-v_1\right|^2}\left(v_2\cdot v_1-\left|v_1\right|^2\right) (v_2-v_1) \end{align}

I considered when this could make $b=0$, such that we get a divide by zero error. An obvious choice is $v_1 = - v_2$ in which case:

\begin{align}b &= -v_2 +\frac{-1}{\left|2v_2\right|^2}\left(-\left|v_2\right|^2 - \left|v_2\right|^2\right)(2v_2)\\ &= -v_2 + v_2 = 0 \end{align}

I believe this is the cause of my errors.

Crystals & Files

Crystal 1

Snapshot of Bi2Se3#1 in Mercury

Crystal1.pdb

    HEADER    CSD ENTRY 1530736
    CRYST1   9.4200   9.4200   9.4200  24.08  24.08  24.08      R-3m
    SCALE1      0.106157 -0.237540 -0.141304       0.000000
    SCALE2      0.000000  0.260181 -0.141304       0.000000
    SCALE3      0.000000  0.000000  0.296076       0.000000
    HETATM    1 Bi1  UNK     1      -2.021  -0.431   2.030  1.00  0.00          BI  
    HETATM    2 Se2  UNK     1      -3.936   1.170   0.696  1.00  0.00          SE  
    HETATM    3 Bi1  UNK     1      -2.021   1.578  -1.348  1.00  0.00          BI  
    HETATM    4 Se2  UNK     1      -3.116  -2.674   0.696  1.00  0.00          SE  
    HETATM    5 Bi1  UNK     1      -1.202  -2.265  -1.348  1.00  0.00          BI  
    HETATM    6 Bi1  UNK     1       1.202   2.265   1.348  1.00  0.00          BI  
    HETATM    7 Se1  UNK     1       0.000   0.000   0.000  1.00  0.00          SE  
    HETATM    8 Se2  UNK     1      -3.116  -0.665  -2.682  1.00  0.00          SE  
    HETATM    9 Bi1  UNK     1       2.021  -1.578   1.348  1.00  0.00          BI  
    HETATM   10 Bi1  UNK     1       2.021   0.431  -2.030  1.00  0.00          BI  
    HETATM   11 Se2  UNK     1       3.116   0.665   2.682  1.00  0.00          SE  
    HETATM   12 Se2  UNK     1       3.116   2.674  -0.696  1.00  0.00          SE  
    HETATM   13 Se2  UNK     1       3.936  -1.170  -0.696  1.00  0.00          SE  
    CONECT    1    2    4    7
    CONECT    2    1    3
    CONECT    3    2    7    8
    CONECT    4    1    5
    CONECT    5    4    7    8
    CONECT    6    7   11   12
    CONECT    7    1    3    5    6
    CONECT    7    9   10
    CONECT    8    3    5
    CONECT    9    7   11   13
    CONECT   10    7   12   13
    CONECT   11    6    9
    CONECT   12    6   10
    CONECT   13    9   10
    MASTER        0    0    0    0    0    0    0    3   13    0   14    0
    END

Crystal 2

Snapshot of Bi2Se3#2 in Mercury

Crystal2.pdb

CRYST1   9.4200   9.4200   9.4200  24.08  24.08  24.08      R-3m
SCALE1      0.106157 -0.237540 -0.141304       0.000000
SCALE2      0.000000  0.260181 -0.141304       0.000000
SCALE3      0.000000  0.000000  0.296076       0.000000
HETATM    1 Bi1  UNK     1       6.579   3.412   2.030  1.00  0.00          BI  
HETATM    2 Bi1  UNK     1       7.399  -0.431   2.030  1.00  0.00          BI  
HETATM    3 Se1  UNK     1       8.600   1.834   3.378  1.00  0.00          SE  
HETATM    4 Se2  UNK     1       5.484   1.170   0.696  1.00  0.00          SE  
HETATM    5 Bi1  UNK     1       7.399   1.578  -1.348  1.00  0.00          BI  
HETATM    6 Se1  UNK     1       8.600   3.843   0.000  1.00  0.00          SE  
HETATM    7 Bi1  UNK     1      10.622   2.265   1.348  1.00  0.00          BI  
HETATM    8 Se1  UNK     1       9.420   0.000   0.000  1.00  0.00          SE  
HETATM    9 Se2  UNK     1      11.717   4.508   2.682  1.00  0.00          SE  
HETATM   10 Se2  UNK     1      12.536   0.665   2.682  1.00  0.00          SE  
HETATM   11 Se2  UNK     1      12.536   2.674  -0.696  1.00  0.00          SE  
CONECT    1    3    4    6
CONECT    2    3    4    8
CONECT    3    1    2    7
CONECT    4    1    2    5
CONECT    5    4    6    8
CONECT    6    1    5    7
CONECT    7    3    6    8    9
CONECT    7   10   11
CONECT    8    2    5    7
CONECT    9    7
CONECT   10    7
CONECT   11    7
MASTER        0    0    0    0    0    0    0    3   11    0   12    0
END
$\endgroup$

1 Answer 1

1
$\begingroup$

When you come to import the .pdb file, in the import window, choose in Sticks/Bonds options section the Type > Normal instead of Dupliverts.

This will basically make the error disappear while getting single colored bonds

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .