[Bf-extensions-cvs] SVN commit: /data/svn/bf-extensions [3946] trunk/py/scripts/addons/ io_mesh_pdb: As in the case of the XYZ IE, names of classes and functions were changed,
Clemens Barth
barth at root-1.de
Fri Nov 9 22:53:50 CET 2012
Revision: 3946
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-extensions&revision=3946
Author: blendphys
Date: 2012-11-09 21:53:49 +0000 (Fri, 09 Nov 2012)
Log Message:
-----------
As in the case of the XYZ IE, names of classes and functions were changed,
according to the "Style Guide for Python Code"
(http://www.python.org/dev/peps/pep-0008/) and the recent review
(http://codereview.appspot.com/6815052). Some slight changes were done, too.
Extensive tests have shown that the code is still well working.
Blendphys
Modified Paths:
--------------
trunk/py/scripts/addons/io_mesh_pdb/__init__.py
trunk/py/scripts/addons/io_mesh_pdb/export_pdb.py
trunk/py/scripts/addons/io_mesh_pdb/import_pdb.py
Modified: trunk/py/scripts/addons/io_mesh_pdb/__init__.py
===================================================================
--- trunk/py/scripts/addons/io_mesh_pdb/__init__.py 2012-11-09 20:07:49 UTC (rev 3945)
+++ trunk/py/scripts/addons/io_mesh_pdb/__init__.py 2012-11-09 21:53:49 UTC (rev 3946)
@@ -24,7 +24,7 @@
#
# Start of project : 2011-08-31 by Clemens Barth
# First publication in Blender : 2011-11-11
-# Last modified : 2012-11-03
+# Last modified : 2012-11-09
#
# Acknowledgements
# ================
@@ -49,10 +49,7 @@
"category": "Import-Export"
}
-import os
-import io
import bpy
-import bmesh
from bpy.types import Operator, Panel
from bpy_extras.io_utils import ImportHelper, ExportHelper
from bpy.props import (StringProperty,
@@ -67,9 +64,8 @@
# -----------------------------------------------------------------------------
# GUI
-
# This is the class for the file dialog of the importer.
-class CLASS_ImportPDB(Operator, ImportHelper):
+class ImportPDB(Operator, ImportHelper):
bl_idname = "import_mesh.pdb"
bl_label = "Import Protein Data Bank(*.pdb)"
bl_options = {'PRESET', 'UNDO'}
@@ -183,7 +179,7 @@
filepath_pdb = bpy.path.abspath(self.filepath)
# Execute main routine
- atom_number = import_pdb.DEF_atom_pdb_main(
+ atom_number = import_pdb.import_pdb(
self.use_mesh,
self.mesh_azimuth,
self.mesh_zenith,
@@ -206,9 +202,8 @@
return {'FINISHED'}
-
# This is the class for the file dialog of the exporter.
-class CLASS_ExportPDB(Operator, ExportHelper):
+class ExportPDB(Operator, ExportHelper):
bl_idname = "export_mesh.pdb"
bl_label = "Export Protein Data Bank(*.pdb)"
filename_ext = ".pdb"
@@ -230,31 +225,29 @@
row.prop(self, "atom_pdb_export_type")
def execute(self, context):
- # This is in order to solve this strange 'relative path' thing.
- export_pdb.ATOM_PDB_FILEPATH = bpy.path.abspath(self.filepath)
- export_pdb.DEF_atom_pdb_export(self.atom_pdb_export_type)
+ export_pdb.export_pdb(self.atom_pdb_export_type,
+ bpy.path.abspath(self.filepath))
return {'FINISHED'}
# The entry into the menu 'file -> import'
-def DEF_menu_func_import(self, context):
- self.layout.operator(CLASS_ImportPDB.bl_idname, text="Protein Data Bank (.pdb)")
+def menu_func_import(self, context):
+ self.layout.operator(ImportPDB.bl_idname, text="Protein Data Bank (.pdb)")
# The entry into the menu 'file -> export'
-def DEF_menu_func_export(self, context):
- self.layout.operator(CLASS_ExportPDB.bl_idname, text="Protein Data Bank (.pdb)")
+def menu_func_export(self, context):
+ self.layout.operator(ExportPDB.bl_idname, text="Protein Data Bank (.pdb)")
-
def register():
bpy.utils.register_module(__name__)
- bpy.types.INFO_MT_file_import.append(DEF_menu_func_import)
- bpy.types.INFO_MT_file_export.append(DEF_menu_func_export)
+ bpy.types.INFO_MT_file_import.append(menu_func_import)
+ bpy.types.INFO_MT_file_export.append(menu_func_export)
def unregister():
bpy.utils.unregister_module(__name__)
- bpy.types.INFO_MT_file_import.remove(DEF_menu_func_import)
- bpy.types.INFO_MT_file_export.remove(DEF_menu_func_export)
+ bpy.types.INFO_MT_file_import.remove(menu_func_import)
+ bpy.types.INFO_MT_file_export.remove(menu_func_export)
if __name__ == "__main__":
Modified: trunk/py/scripts/addons/io_mesh_pdb/export_pdb.py
===================================================================
--- trunk/py/scripts/addons/io_mesh_pdb/export_pdb.py 2012-11-09 20:07:49 UTC (rev 3945)
+++ trunk/py/scripts/addons/io_mesh_pdb/export_pdb.py 2012-11-09 21:53:49 UTC (rev 3946)
@@ -17,32 +17,17 @@
# ##### END GPL LICENSE BLOCK #####
import bpy
-import io
-import math
-import os
-import copy
-from math import pi, cos, sin
-from mathutils import Vector, Matrix
-from copy import copy
from . import import_pdb
-ATOM_PDB_FILEPATH = ""
-ATOM_PDB_PDBTEXT = ( "REMARK This pdb file has been created with Blender "
- + "and the addon Atomic Blender - PDB\n"
- + "REMARK For more details see wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Import-Export/PDB\n"
- + "REMARK\n"
- + "REMARK\n")
-
-
-class CLASS_atom_pdb_atoms_export(object):
+class AtomPropExport(object):
__slots__ = ('element', 'location')
def __init__(self, element, location):
self.element = element
self.location = location
-def DEF_atom_pdb_export(obj_type):
+def export_pdb(obj_type, filepath_pdb):
list_atoms = []
for obj in bpy.context.selected_objects:
@@ -54,7 +39,7 @@
continue
name = ""
- for element in import_pdb.ATOM_PDB_ELEMENTS_DEFAULT:
+ for element in import_pdb.ELEMENTS_DEFAULT:
if element[1] in obj.name:
if element[2] == "Vac":
name = "X"
@@ -70,18 +55,19 @@
if len(obj.children) != 0:
for vertex in obj.data.vertices:
location = obj.matrix_world*vertex.co
- list_atoms.append(CLASS_atom_pdb_atoms_export(
- name,
- location))
+ list_atoms.append(AtomPropExport(name, location))
else:
if not obj.parent:
location = obj.location
- list_atoms.append(CLASS_atom_pdb_atoms_export(
- name,
- location))
+ list_atoms.append(AtomPropExport(name, location))
- pdb_file_p = open(ATOM_PDB_FILEPATH, "w")
- pdb_file_p.write(ATOM_PDB_PDBTEXT)
+ pdb_file_p = open(filepath_pdb, "w")
+ pdb_file_p.write("REMARK This pdb file has been created with Blender "
+ "and the addon Atomic Blender - PDB\n"
+ "REMARK For more details see wiki.blender.org/index.php/"
+ "Extensions:2.6/Py/Scripts/Import-Export/PDB\n"
+ "REMARK\n"
+ "REMARK\n")
for i, atom in enumerate(list_atoms):
string = "ATOM %6d%3s%24.3f%8.3f%8.3f%6.2f%6.2f%12s\n" % (
Modified: trunk/py/scripts/addons/io_mesh_pdb/import_pdb.py
===================================================================
--- trunk/py/scripts/addons/io_mesh_pdb/import_pdb.py 2012-11-09 20:07:49 UTC (rev 3945)
+++ trunk/py/scripts/addons/io_mesh_pdb/import_pdb.py 2012-11-09 21:53:49 UTC (rev 3946)
@@ -17,11 +17,8 @@
# ##### END GPL LICENSE BLOCK #####
import bpy
-import io
-import math
import os
-import copy
-from math import pi, cos, sin
+from math import pi, cos, sin, sqrt, ceil
from mathutils import Vector, Matrix
from copy import copy
@@ -40,7 +37,7 @@
# charge states for any atom are listed, if existing.
# The list is fixed and cannot be changed ... (see below)
-ATOM_PDB_ELEMENTS_DEFAULT = (
+ELEMENTS_DEFAULT = (
( 1, "Hydrogen", "H", ( 1.0, 1.0, 1.0), 0.32, 0.32, 0.79 , -1 , 1.54 ),
( 2, "Helium", "He", ( 0.85, 1.0, 1.0), 0.93, 0.93, 0.49 ),
( 3, "Lithium", "Li", ( 0.8, 0.50, 1.0), 1.23, 1.23, 2.05 , 1 , 0.68 ),
@@ -152,14 +149,14 @@
# This list here contains all data of the elements and will be used during
# runtime. It is a list of classes.
# During executing Atomic Blender, the list will be initialized with the fixed
-# data from above via the class structure below (CLASS_atom_pdb_Elements). We
+# data from above via the class structure below (ElementProp). We
# have then one fixed list (above), which will never be changed, and a list of
# classes with same data. The latter can be modified via loading a separate
# custom data file.
-ATOM_PDB_ELEMENTS = []
+ELEMENTS = []
# This is the class, which stores the properties for one element.
-class CLASS_atom_pdb_Elements(object):
+class ElementProp(object):
__slots__ = ('number', 'name', 'short_name', 'color', 'radii', 'radii_ionic')
def __init__(self, number, name, short_name, color, radii, radii_ionic):
self.number = number
@@ -170,7 +167,7 @@
self.radii_ionic = radii_ionic
# This is the class, which stores the properties of one atom.
-class CLASS_atom_pdb_atom(object):
+class AtomProp(object):
__slots__ = ('element', 'name', 'location', 'radius', 'color', 'material')
def __init__(self, element, name, location, radius, color, material):
self.element = element
@@ -181,7 +178,7 @@
self.material = material
# This is the class, which stores the two atoms of one stick.
-class CLASS_atom_pdb_stick(object):
+class StickProp(object):
__slots__ = ('atom1', 'atom2', 'number', 'dist')
def __init__(self, atom1, atom2, number, dist):
self.atom1 = atom1
@@ -189,15 +186,14 @@
self.number = number
self.dist = dist
-
# -----------------------------------------------------------------------------
# Some basic routines
-def DEF_atom_pdb_read_elements():
+def read_elements():
- ATOM_PDB_ELEMENTS[:] = []
+ ELEMENTS[:] = []
- for item in ATOM_PDB_ELEMENTS_DEFAULT:
+ for item in ELEMENTS_DEFAULT:
# All three radii into a list
radii = [item[4],item[5],item[6]]
@@ -205,22 +201,22 @@
# empty list.
radii_ionic = []
- li = CLASS_atom_pdb_Elements(item[0],item[1],item[2],item[3],
+ li = ElementProp(item[0],item[1],item[2],item[3],
radii,radii_ionic)
- ATOM_PDB_ELEMENTS.append(li)
+ ELEMENTS.append(li)
# filepath_pdb: path to pdb file
# radiustype : '0' default
# '1' atomic radii
# '2' van der Waals
-def DEF_atom_pdb_read_pdb_file(filepath_pdb,radiustype):
+def read_pdb_file(filepath_pdb, radiustype):
# The list of all atoms as read from the PDB file.
all_atoms = []
# Open the pdb file ...
- filepath_pdb_p = io.open(filepath_pdb, "r")
+ filepath_pdb_p = open(filepath_pdb, "r")
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list