Beispiel #1
0
    def do(self):
        cache = context.application.cache

        graph = create_molecular_graph(cache.nodes)
        parent = cache.node

        Frame = context.application.plugins.get_node("Frame")
        for group in graph.independent_vertices:
            atoms = [graph.molecule.atoms[i] for i in group]
            new_positions = self.calc_new_positions(group, atoms, graph,
                                                    parent)
            if new_positions is None:
                # this happens for groups of atoms that are inherently periodic.
                continue
            frame = Frame(name=chemical_formula(atoms)[1])
            primitive.Add(frame, parent, index=0)
            for node, atom in zip(group, atoms):
                primitive.Move(atom, frame)
                new_position = new_positions[node]
                translation = Translation(
                    atom.get_parentframe_up_to(parent).inv * new_position)
                primitive.SetProperty(atom, "transformation", translation)
            for atom in atoms:
                # take a copy of the references since they are going to be
                # refreshed (changed and reverted) during the loop.
                for reference in list(atom.references):
                    referent = reference.parent
                    if referent.parent != frame:
                        has_to_move = True
                        for child in referent.children:
                            if child.target.parent != frame:
                                has_to_move = False
                                break
                        if has_to_move:
                            primitive.Move(referent, frame)
Beispiel #2
0
    def do(self):
        cache = context.application.cache

        graph = create_molecular_graph(cache.nodes)
        parent = cache.node

        Frame = context.application.plugins.get_node("Frame")
        for group in graph.independent_nodes:
            atoms = [graph.molecule.atoms[i] for i in group]
            new_positions = self.calc_new_positions(group, atoms, graph, parent)
            frame = Frame(name=chemical_formula(atoms)[1])
            primitive.Add(frame, parent, index=0)
            for node, atom in zip(group, atoms):
                primitive.Move(atom, frame)
                new_position = new_positions[node]
                translation = Translation()
                translation.t = atom.get_parentframe_up_to(parent).vector_apply_inverse(new_position)
                primitive.SetProperty(atom, "transformation", translation)
            for atom in atoms:
                # take a copy of the references since they are going to be
                # refreshed (changed and reverted) during the loop.
                for reference in copy.copy(atom.references):
                    referent = reference.parent
                    if referent.parent != frame:
                        has_to_move = True
                        for child in referent.children:
                            if child.target.parent != frame:
                                has_to_move = False
                                break
                        if has_to_move:
                            primitive.Move(referent, frame)
Beispiel #3
0
 def do(self):
     total, formula = chemical_formula(yield_atoms(context.application.cache.nodes), True)
     if total > 0:
         answer = "Chemical formula: %s" % formula
         answer += "\nNumber of atoms: %i" % total
     else:
         answer = "No atoms found."
     ok_information(answer, markup=True)
Beispiel #4
0
 def do(self):
     total, formula = chemical_formula(
         iter_atoms(context.application.cache.nodes), True)
     if total > 0:
         answer = "Chemical formula: %s" % formula
         answer += "\nNumber of atoms: %i" % total
     else:
         answer = "No atoms found."
     ok_information(answer, markup=True)