Created
February 25, 2015 09:59
-
-
Save anonymous/1f483ffa44288c3f3793 to your computer and use it in GitHub Desktop.
test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# kdArrange v.003 | |
import bmesh | |
import bpy | |
from collections import defaultdict | |
from BioBlender.table_values import values_fi | |
## helper function | |
def bmesh_from_pyverts(verts): | |
''' verts is necessary, edges/faces are optional ''' | |
bm = bmesh.new() | |
add_vert = bm.verts.new | |
bm_verts = [add_vert(co) for co in verts] | |
bm.verts.index_update() | |
return bm | |
''' | |
[x] step 01: first store atoms as {element_name: [co,..], } | |
[ ] step 02: generate singular ordered mesh by adding vertices | |
in clumps of element types. (H,H,H,H,H,H,O,O,O,O,O,O..) | |
[ ] step 03: track start and end index for each element into mapper_obj | |
[ ] step 04: preprocess obj.fi_value = BBinfo.get(') | |
[ ] step 05: get surface mesh. | |
[ ] step 06: for every vertex on surface mesh find closest | |
vertex in proxy_ob, and MLP value | |
''' | |
# step 01 | |
atom_to_fi = defaultdict(list) | |
proxy_obj = defaultdict(list) | |
nstr = '_4GE.001' | |
objs = bpy.data.objects[nstr].children | |
for o in objs: | |
_name = o.BBInfo[12:16].strip() | |
_amino = o.BBInfo[17:20].strip() | |
fi = values_fi[_amino][_name] | |
co = o.location[:] | |
proxy_obj[_name].append(co) # element name | |
atom_to_fi[_name].append(fi) | |
# step 03 | |
# will just hold a fi vale for every vertex in the atom cloud. | |
idx_to_fi = [] | |
mapper_obj = {} | |
verts = [] | |
idx = 0 | |
for key in sorted(proxy_obj.keys()): | |
start = len(verts) | |
verts.extend(proxy_obj[key]) | |
end = len(verts)-1 | |
mapper_obj[key] = (start, end) | |
idx_to_fi.extend(atom_to_fi[key]) | |
texts = bpy.data.texts | |
if 'fi_values.txt' in texts: | |
text_obj_idx_to_fi = texts['fi_values.txt'] | |
else: | |
text_obj_idx_to_fi = texts.new('fi_values.txt') | |
fi_string = '\n'.join(idx_to_fi) | |
text_obj_idx_to_fi.from_string(fi_string) | |
# print(mapper_obj) | |
# {'C': (0, 97), 'N': (98, 124), 'O': (125, 153) ...} | |
# step 02 | |
def generate_or_update(verts): | |
meshes = bpy.data.meshes | |
objs = bpy.data.objects | |
# -- get or create mesh | |
if "proxy_mesh" in meshes: | |
mesh = meshes["proxy_mesh"] | |
else: | |
mesh = bpy.data.meshes.new("proxy_mesh") | |
# -- inject mesh with verts | |
bm = bmesh_from_pyverts(verts) | |
bm.to_mesh(mesh) | |
bm.free() | |
# -- create or update object with new mesh data | |
if "proxy_obj" in objs: | |
obj = objs['proxy_obj'] | |
obj.data = mesh | |
else: | |
obj = bpy.data.objects.new("proxy_obj", mesh) | |
scene = bpy.context.scene | |
scene.objects.link(obj) | |
generate_or_update(verts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment