Exemplo n.º 1
0
from ase.visualize import view
from blase.tools import write_blender, get_polyhedra_kinds, get_bondpairs
import numpy as np
from pprint import pprint
from ase.data import covalent_radii

atoms = read('datas/latino2-trans-p-001-plp-relax.in')
# atoms.pbc = [False, False, False]
# atoms = atoms*[2, 2, 2]
# kind_props = {
# 'Ti': {'radius': 0.6, 'color': [0/255.0, 191/255.0, 56/255.0]},
# 'O': {'radius': 0.6, }
# }

bond_list = get_bondpairs(atoms,
                          cutoff=1.0,
                          rmbonds=[['Ti', 'Ti'], ['La', 'O'], ['La', 'N'],
                                   ['La', 'Ti'], ['La', 'La']])

# bond_list = get_bondpairs(atoms, rmbonds = [['Ti', 'Ti']])
kwargs = {
    'show_unit_cell': 1,
    'engine':
    'BLENDER_WORKBENCH',  #'BLENDER_EEVEE' #'BLENDER_WORKBENCH', CYCLES
    'radii': 0.3,
    # 'bond_cutoff': 1.0,
    'bond_list': bond_list,
    # 'kind_props': kind_props,
    'display': True,
    'polyhedra_dict': {
        'Ti': ['O', 'N']
    },
Exemplo n.º 2
0
    def __init__(self,
                 images,
                 outfile='bout',
                 name=None,
                 rotations=None,
                 scale=1,
                 debug=False,
                 **parameters):
        for k, v in self.default_settings.items():
            setattr(self, k, parameters.pop(k, v))
        #
        self.debug = debug
        if not isinstance(images, list):
            images = [images]
        self.nimages = len(images)
        self.outfile = outfile
        if rotations:
            for rotation in rotations:
                for i in range(self.nimages):
                    images[i].rotate(rotation[0],
                                     rotation[1],
                                     rotate_cell=True)
        #
        self.images = images
        self.atoms = images[0]
        if self.search_pbc_atoms:
            print(self.search_pbc_atoms)
            cl = ConnectivityList(self.atoms,
                                  cutoffs=self.bond_cutoff,
                                  **self.search_pbc_atoms)
            self.atoms = cl.build()
            # view(self.atoms)
            print(self.atoms)
        if self.boundary_list:
            bd = Boundary(self.atoms, self.boundary_list)
            self.atoms = bd.build()
        self.name = name
        if not self.name:
            self.name = self.atoms.symbols.formula.format('abc')
        self.natoms = len(self.atoms)
        self.positions = self.atoms.positions * scale
        self.numbers = self.atoms.get_atomic_numbers()
        self.symbols = self.atoms.get_chemical_symbols()
        self.cell = self.atoms.get_cell() * scale
        self.celllinewidth = self.celllinewidth * scale
        self.bondlinewidth = self.bondlinewidth * scale
        #------------------------------------------------------------
        # atom_kinds
        self.atom_kinds = get_atom_kinds(self.atoms, self.kind_props)
        self.nkinds = len(self.atom_kinds)
        if self.debug:
            print(self.atom_kinds)
        #
        if isinstance(self.colors, dict):
            for kind in self.colors:
                self.atom_kinds[kind]['color'] = self.colors[kind]
        if isinstance(self.balltypes, str):
            for kind in self.atom_kinds:
                self.atom_kinds[kind]['balltype'] = self.balltypes
        elif isinstance(self.balltypes, dict):
            for kind in self.balltypes:
                self.atom_kinds[kind]['balltype'] = self.balltypes[kind]
        #
        if isinstance(self.transmits, float):
            for kind in self.atom_kinds:
                self.atom_kinds[kind]['transmit'] = self.transmits
        elif isinstance(self.transmits, dict):
            for kind in self.transmits:
                self.atom_kinds[kind]['transmit'] = self.transmits[kind]
        if self.radii is None:
            self.radii = scale
        elif isinstance(self.radii, float):
            for kind in self.atom_kinds:
                self.atom_kinds[kind]['radius'] *= self.radii * scale
        elif isinstance(self.radii, dict):
            for kind in self.radii:
                self.atom_kinds[kind]['radius'] *= self.radii[kind] * scale
        #------------------------------------------------------------
        # bond_kinds
        if not self.bond_list and self.bond_cutoff:
            self.bond_list = get_bondpairs(self.atoms, cutoff=self.bond_cutoff)
        # print(self.bond_list)
        self.bond_kinds = get_bond_kinds(self.atoms, self.atom_kinds,
                                         self.bond_list)
        #------------------------------------------------------------
        self.polyhedra_kinds = get_polyhedra_kinds(
            self.atoms,
            self.atom_kinds,
            self.bond_list,
            polyhedra_dict=self.polyhedra_dict)
        #------------------------------------------------------------
        # cell
        # disp = atoms.get_celldisp().flatten()
        if self.show_unit_cell == 'default':
            if self.atoms.pbc.any():
                self.show_unit_cell = True
            else:
                self.show_unit_cell = False
        self.cell_vertices = None
        if self.show_unit_cell:
            cell_vertices = np.empty((2, 2, 2, 3))
            for c1 in range(2):
                for c2 in range(2):
                    for c3 in range(2):
                        cell_vertices[c1, c2, c3] = np.dot([c1, c2, c3],
                                                           self.cell)
            cell_vertices.shape = (8, 3)
            self.cell_vertices = cell_vertices
        #
        if self.bbox is None:
            bbox = np.zeros([3, 2])
            # print(self.positions)
            R = self.atom_kinds[max(
                self.atom_kinds,
                key=lambda x: self.atom_kinds[x]['radius'])]['radius']
            for i in range(3):
                P1 = (self.positions[:, i] - R).min(0)
                P2 = (self.positions[:, i] + R).max(0)
                if self.show_unit_cell:
                    C1 = (self.cell_vertices[:, i] - self.celllinewidth).min(0)
                    C2 = (self.cell_vertices[:, i] + self.celllinewidth).max(0)
                    P1 = min(P1, C1)
                    P2 = max(P2, C2)
                bbox[i] = [P1, P2]
            self.bbox = bbox
            self.w = self.bbox[0][1] - self.bbox[0][0]
            self.h = self.bbox[1][1] - self.bbox[1][0]
        else:
            self.w = (self.bbox[0][1] - self.bbox[0][0]) * scale
            self.h = (self.bbox[1][1] - self.bbox[1][0]) * scale
        # print(self.bbox)
        # print(self.h, self.w)
        self.com = np.mean(self.bbox, axis=1)
        if self.camera_target is None:
            self.camera_target = self.com

        if not self.ortho_scale:
            if self.w > self.h:
                self.ortho_scale = self.w + 1
            else:
                self.ortho_scale = self.h + 1
        print(self.w, self.h, self.ortho_scale)
        #
        constr = self.atoms.constraints
        self.constrainatoms = []
        for c in constr:
            if isinstance(c, FixAtoms):
                for n, i in enumerate(c.index):
                    self.constrainatoms += [i]
        #
        self.material_styles_dict = {
            'jmol': {
                'Specular': 1.0,
                'Roughness': 0.001,
                'Metallic': 1.0
            },
            'ase3': {
                'Metallic': 1.0,
                'Roughness': 0.001
            },
            'ceramic': {
                'Subsurface': 0.1,
                'Metallic': 0.02,
                'Specular': 0.5,
                'Roughness': 0.0
            },
            'plastic': {
                'Metallic': 0.0,
                'Specular': 0.5,
                'Roughness': 0.7,
                'Sheen Tint': 0.5,
                'Clearcoat Roughness': 0.03,
                'IOR': 1.6
            },
            'glass': {
                'Metallic': 0.0,
                'Specular': 0.5,
                'Roughness': 0.0,
                'Clearcoat': 0.5,
                'Clearcoat Roughness': 0.03,
                'IOR': 1.45,
                'Transmission': 0.98
            },
            'blase': {
                'Metallic': 0.02,
                'Specular': 0.2,
                'Roughness': 0.4,
            },
            'mirror': {
                'Metallic': 0.99,
                'Specular': 2.0,
                'Roughness': 0.001
            },
        }
        # ------------------------------------------------------------------------
        # remove all objects, Select objects by type
        clean_default()
        # 'AtomProp'.
        ALL_FRAMES = []
        # A list of ALL balls which are put into the scene
        self.STRUCTURE = []
        # COLLECTION
        # Before we start to draw the atoms, we first create a collection for the
        # atomic structure. All atoms (balls) are put into this collection.
        if self.build_collection:
            self.coll_name = os.path.basename(self.name) + '_blase'
            self.scene = bpy.context.scene
            self.coll = bpy.data.collections.new(self.coll_name)
            self.scene.collection.children.link(self.coll)
            self.coll_cell = bpy.data.collections.new('cell')
            self.coll_atom_kinds = bpy.data.collections.new('atoms')
            self.coll_bond_kinds = bpy.data.collections.new('bonds')
            self.coll_polyhedra_kinds = bpy.data.collections.new('polyhedras')
            self.coll_isosurface = bpy.data.collections.new('isosurfaces')
            self.coll_instancer = bpy.data.collections.new('instancers')
            self.coll.children.link(self.coll_cell)
            self.coll.children.link(self.coll_atom_kinds)
            self.coll.children.link(self.coll_bond_kinds)
            self.coll.children.link(self.coll_polyhedra_kinds)
            self.coll.children.link(self.coll_isosurface)
            self.coll.children.link(self.coll_instancer)
        # ------------------------------------------------------------------------
        # DRAWING THE ATOMS
        bpy.ops.object.select_all(action='DESELECT')
        # CAMERA and LIGHT SOURCES
        if self.camera:
            self.add_camera()
        if self.light:
            self.add_light()
        #
        if self.world:
            world = self.scene.world
            world.use_nodes = True
            node_tree = world.node_tree
            rgb_node = node_tree.nodes.new(type="ShaderNodeRGB")
            rgb_node.outputs["Color"].default_value = (1, 1, 1, 1)
            node_tree.nodes["Background"].inputs[
                "Strength"].default_value = 1.0
            node_tree.links.new(rgb_node.outputs["Color"],
                                node_tree.nodes["Background"].inputs["Color"])
Exemplo n.º 3
0
# Move molecule to 3.5Ang from surface, and translate one unit cell in xy
atoms.positions[-12:, 2] += atoms.positions[:-12, 2].max() + 3.5
atoms.positions[-12:, :2] += cell[:2]
atoms.cell[0][0] += 10
# Mark a single unit cell
# atoms.cell = cell
# view(atoms)

# View used to start ag, and find desired viewing angle
#view(atoms)
# rot = '35x,63y,36z'  # found using ag: 'view -> rotate'

atoms.rotate(90, 'y')
# view(atoms)
bondatoms = get_bondpairs(atoms,
                          cutoff=1.2,
                          rmbonds=[['Na', 'Na'], ['Cl', 'Cl']])
# print(bondatoms)
kwargs = {
    # 'show_unit_cell': 1,
    'radii': 0.6,
    # 'functions': [['draw_plane', {'size': 200, 'loc': (0, 0, -1.0)}]],
    'bonds': 'all',
    'display': True,
    'radii': {
        'C': 0.8,
        'H': 0.8
    },
    'bondlist': bondatoms,
    'bondlinewidth': 0.4,  # radius of the cylinders representing bonds
    'outfile': 'figs/NaCl_C6H6',
Exemplo n.º 4
0
from ase.io import read, write
from ase.visualize import view
from blase.tools import write_blender, get_polyhedra_kinds, get_bondpairs
import numpy as np
from pprint import pprint
from ase.data import covalent_radii


atoms = read('datas/tio2.cif')
# view(atoms)
bond_list = get_bondpairs(atoms, cutoff=1.0, rmbonds=[['Ti', 'Ti']])
# pprint(bond_list)
kwargs = {'name': 'tio2',
          'show_unit_cell': 1, 
          'engine': 'BLENDER_WORKBENCH', #'BLENDER_EEVEE' #'BLENDER_WORKBENCH', CYCLES
          'radii': 0.6,
          # 'bond_cutoff': 1.0,
          'bond_list': bond_list,
          'display': True,
          # 'search_pbc': {'bonds_dict': {'O': [['Ti'], -1]}},
          'polyhedra_dict': {'Ti': ['O']},
          'outfile': 'figs/test-search-bonds',
          }
write_blender(atoms, **kwargs)