From f705507e85fa59b7643bd30295d8b8b9b566d104 Mon Sep 17 00:00:00 2001
From: Clemens Barth <barth@root-1.de>
Date: Wed, 14 Dec 2011 16:30:51 +0000
Subject: [PATCH] Dear all.

Some changes in the code, which reads PDB files, have
been done.

If you find bugs, please let me know. Thx.

Cheers,

Blendphys.
---
 io_mesh_pdb/__init__.py   |  2 +-
 io_mesh_pdb/import_pdb.py | 40 ++++++++++++++++++++++++++++++---------
 2 files changed, 32 insertions(+), 10 deletions(-)

diff --git a/io_mesh_pdb/__init__.py b/io_mesh_pdb/__init__.py
index 4868ac25d..c08c642ee 100644
--- a/io_mesh_pdb/__init__.py
+++ b/io_mesh_pdb/__init__.py
@@ -464,7 +464,7 @@ class CLASS_atom_pdb_load_button(Operator):
 # This is the class for the file dialog.
 class ImportPDB(Operator, ImportHelper):
     bl_idname = "import_mesh.pdb"
-    bl_label  = "Import Protein Data Bank (*.pdb)"
+    bl_label  = "Import Protein Data Bank(*.pdb)"
 
     filename_ext = ".pdb"
     filter_glob  = StringProperty(default="*.pdb", options={'HIDDEN'},)
diff --git a/io_mesh_pdb/import_pdb.py b/io_mesh_pdb/import_pdb.py
index 8a860cbbc..69008142b 100644
--- a/io_mesh_pdb/import_pdb.py
+++ b/io_mesh_pdb/import_pdb.py
@@ -557,17 +557,39 @@ def DEF_atom_pdb_main(use_mesh,Ball_azimuth,Ball_zenith,
         elif "ATOM" in line or "HETATM" in line:
 
             # What follows is due to deviations which appear from PDB to
-            # PDB file. It is very special. PLEASE, DO NOT CHANGE! From here ...
-            short_name = line[13:14]
-            if short_name.isupper() == True:
+            # PDB file. It is very special!
+            # 
+            # PLEASE, DO NOT CHANGE! ............................... from here
+            if line[12:13] == " " or line[12:13].isdigit() == True:
+                short_name = line[13:14]
                 if line[14:15].islower() == True:
-                    short_name = short_name + line[14:15]
-            else:
+                    short_name = short_name + line[14:15]            
+            elif line[12:13].isupper() == True:
                 short_name = line[12:13]
-                if short_name.isupper() == True:
-                    if line[13:14].islower() == True:
-                        short_name = short_name + line[13:14]
-            # ... to here.
+                if line[13:14].isalpha() == True:
+                    short_name = short_name + line[13:14]
+            else:
+                print("Atomic Blender: Strange error in PDB file.\n" 
+                      "Look for element names at positions 13-16 and 78-79.\n")
+                return -1
+                
+            if len(line) >= 78:
+            
+                if line[76:77] == " ":
+                    short_name2 = line[76:77]
+                else:
+                    short_name2 = line[76:78]
+                
+                if short_name2.isalpha() == True:
+                    FOUND = False
+                    for element in ATOM_PDB_ELEMENTS:
+                        if str.upper(short_name2) == str.upper(element.short_name):
+                            FOUND = True
+                            break
+                    if FOUND == False:
+                        short_name = short_name2
+            # ....................................................... to here.
+            
 
             # Go through all elements and find the element of the current atom.
             FLAG_FOUND = False
-- 
GitLab