def do(self): graph = create_molecular_graph(context.application.cache.nodes) match_generator = GraphSearch(RingPattern(20)) rings = list(match_generator(graph)) ring_distribution_window = RingDistributionWindow() ring_distribution_window.show(rings, graph)
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)
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)
def do(self): frame_ref = context.application.cache.nodes[0] graph_ref = create_molecular_graph([frame_ref]) try: match_generator = GraphSearch(EqualPattern(graph_ref)) except PatternError, e: raise UserError("Could not setup a graph match definition to clone the order.")
def do(self): for key, val in self.parameters.__dict__.iteritems(): if isinstance(val, Expression): val.compile_as("<%s>" % key) val.variables = (key[7:11], ) parent = context.application.cache.common_parent if parent is None: parent = context.application.model.universe angles = [] graph = create_molecular_graph(context.application.cache.nodes) match_definition = BendingAnglePattern(criteria_sets=[ CriteriaSet( thing_criteria={ 0: IndexToAtoms(self.parameters.filter_atom1), 1: IndexToAtoms(self.parameters.filter_atom2), 2: IndexToAtoms(self.parameters.filter_atom3), }, relation_criteria={ 0: IndexToBonds(self.parameters.filter_bond12), 1: IndexToBonds(self.parameters.filter_bond23), }, ) ], ) try: atoms = graph.molecule.atoms match_generator = GraphSearch(match_definition) for match in match_generator(graph): point1 = atoms[match.forward[0]].get_absolute_frame().t point2 = atoms[match.forward[1]].get_absolute_frame().t point3 = atoms[match.forward[2]].get_absolute_frame().t delta1 = parent.shortest_vector(point2 - point1) delta2 = parent.shortest_vector(point2 - point3) if numpy.linalg.norm(delta1) > 1e-8 and \ numpy.linalg.norm(delta2) > 1e-8: angles.append(angle(delta1, delta2)) except: raise UserError( "An error occured while sampling the bending angles.", "If this is an error in one of the filter expressions,\n" + "one should see the expression mentioned below as <filter_...>.\n\n" ) comments = [ "atom 1 filter expression: %s" % self.parameters.filter_atom1.code, "bond 1-2 filter expression: %s" % self.parameters.filter_bond12.code, "atom 2 filter expression: %s" % self.parameters.filter_atom2.code, "bond 2-3 filter expression: %s" % self.parameters.filter_bond23.code, "atom 3 filter expression: %s" % self.parameters.filter_atom3.code, ] if len(angles) > 0: distribution_dialog = DistributionDialog() distribution_dialog.run(numpy.array(angles), "Angle", "Bending angle", comments) else: raise UserError("No bending angles match the given criteria.")
def do(self): frame_ref = context.application.cache.nodes[0] graph_ref = create_molecular_graph([frame_ref]) try: match_generator = GraphSearch(EqualPattern(graph_ref)) except GraphError, e: raise UserError( "Could not setup a graph match definition to clone the order.")
def do(self): for key, val in self.parameters.__dict__.iteritems(): if isinstance(val, Expression): val.compile_as("<%s>" % key) val.variables = (key[7:11],) parent = context.application.cache.common_parent if parent is None: parent = context.application.model.universe angles = [] graph = create_molecular_graph(context.application.cache.nodes) match_definition = BendingAnglePattern( criteria_sets=[CriteriaSet( thing_criteria={ 0: IndexToAtoms(self.parameters.filter_atom1), 1: IndexToAtoms(self.parameters.filter_atom2), 2: IndexToAtoms(self.parameters.filter_atom3), }, relation_criteria={ 0: IndexToBonds(self.parameters.filter_bond12), 1: IndexToBonds(self.parameters.filter_bond23), }, )], ) try: atoms = graph.molecule.atoms match_generator = GraphSearch(match_definition) for match in match_generator(graph): point1 = atoms[match.forward[0]].get_absolute_frame().t point2 = atoms[match.forward[1]].get_absolute_frame().t point3 = atoms[match.forward[2]].get_absolute_frame().t delta1 = parent.shortest_vector(point2 - point1) delta2 = parent.shortest_vector(point2 - point3) if numpy.linalg.norm(delta1) > 1e-8 and \ numpy.linalg.norm(delta2) > 1e-8: angles.append(angle(delta1, delta2)) except: raise UserError( "An error occured while sampling the bending angles.", "If this is an error in one of the filter expressions,\n" + "one should see the expression mentioned below as <filter_...>.\n\n" ) comments = [ "atom 1 filter expression: %s" % self.parameters.filter_atom1.code, "bond 1-2 filter expression: %s" % self.parameters.filter_bond12.code, "atom 2 filter expression: %s" % self.parameters.filter_atom2.code, "bond 2-3 filter expression: %s" % self.parameters.filter_bond23.code, "atom 3 filter expression: %s" % self.parameters.filter_atom3.code, ] if len(angles) > 0: distribution_dialog = DistributionDialog() distribution_dialog.run(numpy.array(angles), "Angle", "Bending angle", comments) else: raise UserError("No bending angles match the given criteria.")
def __call__(self, f, universe, folder, nodes=None): atom_counter = 0 if nodes is None: nodes = [universe] graph = create_molecular_graph([universe]) names = [atom.name for atom in graph.molecule.atoms] charges = [atom.extra.get("charge", 0.0) for atom in graph.molecule.atoms] psf_file = PSFFile() psf_file.add_molecular_graph(graph, atom_types=names, charges=charges) psf_file.dump(f)
def do(self): # Get the molecular graph of the molecule in the selection parent = context.application.cache.node graph = create_molecular_graph([parent], parent) if graph.molecule.size == 0: raise UserError("Could not get molecular graph.", "Make sure that the selected frame contains a molecule.") # Guessed and original geometry opt_coords = guess_geometry(graph).coordinates org_coords = graph.molecule.coordinates coords_to_zeobuilder(org_coords, opt_coords, graph.molecule.atoms, parent)
class CloneOrder(Immediate): description = "Apply the order of the first selection to all the other." menu_info = MenuInfo("default/_Object:tools/_Molecular:rearrange", "_Clone order", order=(0, 4, 1, 5, 0, 3)) authors = [authors.toon_verstraelen] @staticmethod def analyze_selection(): if not Immediate.analyze_selection(): return False cache = context.application.cache if len(cache.nodes) < 2: return False Frame = context.application.plugins.get_node("Frame") for cls in cache.classes: if not issubclass(cls, Frame): return False return True def do(self): frame_ref = context.application.cache.nodes[0] graph_ref = create_molecular_graph([frame_ref]) try: match_generator = GraphSearch(EqualPattern(graph_ref)) except GraphError, e: raise UserError( "Could not setup a graph match definition to clone the order.") some_failed = False all_failed = True for frame_other in context.application.cache.nodes[1:]: graph_other = create_molecular_graph([frame_other]) try: match = match_generator(graph_other).next() all_failed = False except (StopIteration, GraphError): some_failed = True continue moves = [(index1, graph_other.molecule.atoms[index2]) for index1, index2 in match.forward.iteritems()] moves.sort() for new_index, atom2 in moves: primitive.Move(atom2, frame_other, new_index) if all_failed: raise UserError("None of the atom orders could be cloned.") elif some_failed: ok_error( "Some molecules/frames did not match the first frame, so they are not reordered." )
def do(self): # Get the molecular graph of the molecule in the selection parent = context.application.cache.node graph = create_molecular_graph([parent], parent) if graph.molecule.size == 0: raise UserError( "Could not get molecular graph.", "Make sure that the selected frame contains a molecule.") # Guessed and original geometry opt_coords = tune_geometry(graph, graph.molecule).coordinates org_coords = graph.molecule.coordinates coords_to_zeobuilder(org_coords, opt_coords, graph.molecule.atoms, parent, graph)
def do(self): # Get the molecular graph of the molecule in the selection parent = context.application.cache.node graph = create_molecular_graph([parent], parent) if graph.molecule.size == 0: raise UserError("Could not get molecular graph.", "Make sure that the selected frame contains a molecule.") # Guessed and original geometry unitcell = context.application.model.universe.cell unitcell_reciproke = context.application.model.universe.cell_reciproke unitcell_active = context.application.model.universe.cell_active # not entirely sure where to set this in zeobuilder opt_coords = guess_geometry(graph, unitcell_active, unitcell, unitcell_reciproke).coordinates org_coords = graph.molecule.coordinates coords_to_zeobuilder(org_coords, opt_coords, graph.molecule.atoms, parent, graph)