Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolution #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions blender_importASE/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ class ImportASEMolecule(bpy.types.Operator, ImportHelper):
min=0.0,
soft_max=10,
)

resolution: bpy.props.IntProperty(
name='resolution',
description='resolution of bonds and atoms',
default=16,
)

colorbonds: bpy.props.BoolProperty(
name='colorbonds',
description="Color the bonds according to the surrounding atoms",
Expand Down Expand Up @@ -122,6 +129,7 @@ def draw(self, context):
row = box.row(align=True)
for j in range(3):
row.prop(self, "supercell1", index=i * 3 + j, emboss=False, slider=True)
layout.prop(self, "resolution")
layout.prop(self, "scale")
layout.prop(self, 'colorbonds')
layout.prop(self, 'fix_bonds')
Expand All @@ -145,6 +153,7 @@ def execute(self, context):
SUPERCELL = True
break
import_ase_molecule(filepath, file.name, matrix,
resolution=self.resolution,
color=self.color, colorbonds=self.colorbonds, fix_bonds=self.fix_bonds, scale=self.scale,
unit_cell=self.unit_cell, representation=self.representation,
separate_collections=self.separate_collections,
Expand Down
26 changes: 13 additions & 13 deletions blender_importASE/drawobjects.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import ase.neighborlist


def draw_atoms(atoms, scale=1, representation="Balls'n'Sticks"):
def draw_atoms(atoms, scale=1,resolution=16, representation="Balls'n'Sticks"):
cnt = 0
list_of_atoms=[]
# bpy.ops.surface.primitive_nurbs_surface_sphere_add(radius=1, enter_editmode=False, align='WORLD', location=(0.0, 0.0, 0.0), rotation=(0.0, 0.0, 0.0), scale=(0.0, 0.0, 0.0))
bpy.ops.mesh.primitive_uv_sphere_add(location=(0, 0, 0), segments=16, ring_count=16)
bpy.ops.mesh.primitive_uv_sphere_add(location=(0, 0, 0), segments=resolution, ring_count=resolution)
if bpy.app.version[1] == 0: #use_auto_smoot dropped after 4.0
bpy.ops.object.shade_smooth(use_auto_smooth=True)
else:
Expand Down Expand Up @@ -47,7 +47,7 @@ def draw_atoms(atoms, scale=1, representation="Balls'n'Sticks"):
return list_of_atoms


def draw_bonds(atoms):
def draw_bonds(atoms,resolution=16):
list_of_bonds=[]
nl = ase.neighborlist.NeighborList([covalent_radii[atomic_number] * 0.9 for atomic_number in atoms.numbers],
self_interaction=False, bothways=True)
Expand All @@ -59,7 +59,7 @@ def draw_bonds(atoms):
None
# bpy.ops.surface.primitive_nurbs_surface_cylinder_add(radius=1.0, enter_editmode=False, align='WORLD',
# location=(0.0, 0.0, 0.0), rotation=(0.0, 0.0, 0.0), scale=(0.0, 0.0, 0.0))
bond = create_half_bond()
bond = create_half_bond(resolution=resolution)
cnt = 0
for atom in atoms:
if nl.get_neighbors(atom.index)[0].size > 0:
Expand Down Expand Up @@ -98,7 +98,7 @@ def draw_bonds(atoms):
return list_of_bonds,nl


def draw_bonds_new(atoms):
def draw_bonds_new(atoms,resolution=16):
#print("Using Longbond mech")
list_of_bonds=[]
bondlengths=[] # for animation
Expand All @@ -111,8 +111,8 @@ def draw_bonds_new(atoms):
except Exception:
pass
# create half bond
hbond = create_half_bond()
bond = create_full_bond()
hbond = create_half_bond(resolution=resolution)
bond = create_full_bond(resolution=resolution)
cnt = 0
cell = atoms.get_cell()
# make a list of all bonds
Expand All @@ -123,10 +123,10 @@ def draw_bonds_new(atoms):
neighbor_position = atoms.positions[neighbor] + offset.dot(atoms.cell)
# Hier liegt das problem: die Zelle ist nicht 1x1x1
#print(f'PBC: {atoms.pbc}')
if atoms.pbc.all() == True:
if atoms.pbc.all():
#print(atoms.pbc, 'need to check for unit cell')
is_same_unit_cell = is_inside_cell(neighbor_position, cell)
if is_same_unit_cell == True:
if is_same_unit_cell:
dis=round(atoms.get_distance(atom.index,neighbor,mic=False),3)
dismin=round(atoms.get_distance(atom.index,neighbor,mic=True),3)
if dis != dismin:
Expand Down Expand Up @@ -267,9 +267,9 @@ def draw_unit_cell(atoms):
return None


def create_half_bond():
def create_half_bond(resolution=16):
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.mesh.primitive_cylinder_add(vertices=16)
bpy.ops.mesh.primitive_cylinder_add(vertices=resolution)
if bpy.app.version[1] == 0: #use_auto_smoot dropped after 4.0
bpy.ops.object.shade_smooth(use_auto_smooth=True)
else:
Expand All @@ -295,9 +295,9 @@ def create_half_bond():
return bond


def create_full_bond():
def create_full_bond(resolution=16):
bpy.ops.object.select_all(action='DESELECT')
bpy.ops.mesh.primitive_cylinder_add(vertices=16)
bpy.ops.mesh.primitive_cylinder_add(vertices=resolution)
if bpy.app.version[1] == 0: #use_auto_smoot dropped after 4.0
bpy.ops.object.shade_smooth(use_auto_smooth=True)
else:
Expand Down
8 changes: 4 additions & 4 deletions blender_importASE/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from .trajectory import move_atoms, move_bonds,move_longbonds


def import_ase_molecule(filepath, filename, matrix, colorbonds=False, fix_bonds=False, color=0.2, scale=1,
def import_ase_molecule(filepath, filename, matrix, resolution=16, colorbonds=False, fix_bonds=False, color=0.2, scale=1,
unit_cell=False,
representation="Balls'n'Sticks", separate_collections=False,
read_density=True, SUPERCELL=True, shift_cell=False,
Expand Down Expand Up @@ -39,7 +39,7 @@ def import_ase_molecule(filepath, filename, matrix, colorbonds=False, fix_bonds=
layer_collection = bpy.context.view_layer.layer_collection.children[my_coll.name]
bpy.context.view_layer.active_layer_collection = layer_collection
group_atoms(atoms)
list_of_atoms=draw_atoms(atoms, scale=scale, representation=representation)
list_of_atoms=draw_atoms(atoms, scale=scale,resolution=resolution ,representation=representation)
if representation != 'VDW':
if separate_collections:
my_coll = bpy.data.collections.new(
Expand All @@ -48,9 +48,9 @@ def import_ase_molecule(filepath, filename, matrix, colorbonds=False, fix_bonds=
layer_collection = bpy.context.view_layer.layer_collection.children[my_coll.name]
bpy.context.view_layer.active_layer_collection = layer_collection
if fix_bonds:
list_of_bonds,nl,bondlengths=draw_bonds_new(atoms)
list_of_bonds,nl,bondlengths=draw_bonds_new(atoms,resolution=resolution)
else:
list_of_bonds,nl=draw_bonds(atoms)
list_of_bonds,nl=draw_bonds(atoms,resolution=resolution)
if unit_cell is True and atoms.pbc.all() is not False:
if separate_collections:
my_coll = bpy.data.collections.new(
Expand Down
Loading