-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathgui_io.py
143 lines (130 loc) · 4.27 KB
/
gui_io.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
import json
import bpy
from bpy.types import Operator, AddonPreferences
from bpy_extras.io_utils import ImportHelper, ExportHelper
from bpy.props import (
StringProperty,
BoolProperty,
EnumProperty,
IntProperty,
FloatProperty,
)
from ase.io.cube import read_cube_data
from blase.batoms import Batoms
class IMPORT_OT_blase(Operator, ImportHelper):
bl_idname = "import_mesh.blase"
bl_label = "Import blase (*.blase)"
bl_options = {"PRESET", "REGISTER", "UNDO"}
filename_ext = ".blase"
camera: BoolProperty(
name="Camera", default=False,
description="Do you need a camera?")
light: BoolProperty(
name="Light", default=False,
description = "Do you need a light?")
world: BoolProperty(
name="World", default=False,
description = "Do you need a world light?")
model_type: EnumProperty(
name="Type",
description="Choose model",
items=(('0',"Space-filling", "Use ball"),
('1',"Ball-and-stick", "Use ball and stick"),
('2',"Polyhedral","Use polyhedral"),
('3',"Stick", "Use stick")),
default='0',)
ball_type: EnumProperty(
name="Type of ball",
description="Choose model",
items=(('0',"Ball", "Use ball and stick"),
('1',"Meta", "Use ball")),
default='0',)
label: StringProperty(
name = "label",
description = "Label")
bond_cutoff: FloatProperty(
name = "Bond_cutoff", default=1.0, min=0.0001,
description = "Bond cutoff")
show_unit_cell: BoolProperty(
name = "Show_unit_cell", default=False,
description = "Show unit cell")
atomradius: EnumProperty(
name="Type of radius",
description="Choose type of atom radius",
items=(('0', "Pre-defined", "Use pre-defined radius"),
('1', "Atomic", "Use atomic radius"),
('2', "van der Waals", "Use van der Waals radius")),
default='0',)
make_real: FloatProperty(
name = "Make_real", default=False,
description = "")
def draw(self, context):
layout = self.layout
box = layout.box()
row = box.row()
row.label(text="Adding Structure")
box = layout.box()
row = box.row()
row.prop(self, "label")
#
row = layout.row()
row.prop(self, "camera")
row.prop(self, "light")
row.prop(self, "world")
#
box = layout.box()
row = box.row()
# row.label(text="Unit_cell")
row.prop(self, "show_unit_cell")
# Balls
box = layout.box()
row = box.row()
row.label(text="Structure model")
row = box.row()
col = row.column()
col.prop(self, "model_type")
box = layout.box()
row = box.row()
row.active = (self.model_type == "1")
#
def execute(self, context):
# This is to determine the path.
self.inputfile = bpy.path.abspath(self.filepath)
# Execute main routine
import_blase(self.inputfile,
self.model_type,
self.camera,
self.light,
self.world,
self.show_unit_cell,
self.label,
)
return {'FINISHED'}
def import_blase(inputfile,
model_type = '0',
camera = 'True',
light = 'True',
world = 'False',
show_unit_cell = False,
label = None,
):
#
from ase.io import read
print('='*30)
print('Import structure')
print('='*30)
print(model_type)
#
kwargs = {'show_unit_cell': show_unit_cell,
'world': world,
'camera': camera,
'light': light,
}
if inputfile.split('.')[-1] == 'cube':
images, data = read_cube_data(inputfile)
else:
images = read(inputfile)
if not label:
label = inputfile
bobj = Batoms(label = label, atoms = images, model_type=model_type) #, **kwargs)
bobj.draw()