def __init__(self): self._active = False self._value = _Button._MultiStateVariable._create("") self._color = _Button._MultiStateVariable._create(Color.White()) self._sharpness = 0.5 self._size = 1.0 self._ratio = 0.5 self._position = Vector3() self._rotation = Vector3()
def make_menu(self): self.menu = nanome.ui.Menu() self.menu_position = Vector3() self.menu_rotation = Quaternion() self.menu_scale = Vector3() self.last = time.time() self.outstanding = True self.update_menu(self.menu) self.request_menu_transform(0, lambda _1, _2, _3: None) self.set_menu_transform(0, self.menu_position, self.menu_rotation, self.menu_scale) self.request_menu_transform(0, self.check_menu_stats)
def get_complex_center(complex): """Calculate the center of a complex.""" inf = float('inf') min_pos = Vector3(inf, inf, inf) max_pos = Vector3(-inf, -inf, -inf) for atom in complex.atoms: min_pos.x = min(min_pos.x, atom.position.x) min_pos.y = min(min_pos.y, atom.position.y) min_pos.z = min(min_pos.z, atom.position.z) max_pos.x = max(max_pos.x, atom.position.x) max_pos.y = max(max_pos.y, atom.position.y) max_pos.z = max(max_pos.z, atom.position.z) return (min_pos + max_pos) * 0.5
def structure_molecule(model): # type: (Content.Model) -> Molecule molecule = _Molecule._create() molecule._name = model.name chain = _Chain._create() chain._name = "S" molecule._add_chain(chain) residue = _Residue._create() residue._name = "SDF" residue._type = residue._name residue.serial = 1 chain._add_residue(residue) atoms_by_serial = {} for catom in model.atoms: atom = _Atom._create() atom._symbol = catom.symbol atom._serial = catom.serial atom._position = Vector3(catom.x, catom.y, catom.z) atom._name = catom.symbol atom._is_het = True atom._formal_charge = catom.charge residue._add_atom(atom) atoms_by_serial[atom._serial] = atom for cbond in model.bonds: if cbond.serial_atom1 in atoms_by_serial and cbond.serial_atom2 in atoms_by_serial: bond = _Bond._create() bond._atom1 = atoms_by_serial[cbond.serial_atom1] bond._atom2 = atoms_by_serial[cbond.serial_atom2] bond._kind = enums.Kind.safe_cast(cbond.bond_order) residue._add_bond(bond) molecule._associated = model._associated return molecule
def test_matrices(): a = Matrix(3, 4) b = Matrix(4, 3) v = Matrix(4, 1) v[0][0] = 12.5 v[1][0] = 9.36 v[2][0] = 24.1 v[3][0] = 1.0 result_mul = Matrix(3, 3) result_mul[0] = [42, 48, 54] result_mul[1] = [114, 136, 158] result_mul[2] = [186, 224, 262] result_mul_v = Matrix(3, 1) result_mul_v[0][0] = 60.56 result_mul_v[1][0] = 248.4 result_mul_v[2][0] = 436.24 for i in range(12): a[int(i / 4)][int(i % 4)] = i b[int(i / 3)][int(i % 3)] = i assert_equal(a * b, result_mul) assert_equal(a * v, result_mul_v) res_atom_global_pos = Vector3(-20.33947, 0.1491127, -9.878754) complex = struct.Complex() atom = struct.Atom() atom.position.set(7.2, 2.6, -21.56) complex.position.set(-3.197371, -2.314157, 5.071643) complex.rotation.set(0.09196287, 0.4834483, 0.3486853, 0.797646) m = complex.get_complex_to_workspace_matrix() m_inv = complex.get_workspace_to_complex_matrix() atom_global_pos = m * atom.position assert_equal(atom_global_pos, res_atom_global_pos) assert_equal(m_inv * atom_global_pos, atom.position)
def import_file(self, file_text, file_name, ext, button): lines = file_text.split('\n') suffix = ext if ext != 'cif' else 'mmcif' complex = getattr(nanome.api.structure.Complex.io, 'from_' + suffix)(lines=lines) complex.name = file_name complex.position = Vector3() self._plugin.add_bonds([complex], self._plugin.add_to_workspace)
def __init__(self): self._A = 0.0 self._B = 0.0 self._C = 0.0 self._Alpha = 0.0 self._Beta = 0.0 self._Gamma = 0.0 self._Origin = Vector3()
def create_complex(): val = struct.Complex() val.index = 1000 val._molecules = [struct.Molecule(), create_molecule(), struct.Molecule(), create_molecule()] val.boxed = True val.visible = False val.computing = False val.set_current_frame(0) val.name = "COMPLEX_NAME" val._remarks = dict([("key1", "val1"), ("key2","val2"),("key3", "val3"), ("key4","val4")]) val.position = Vector3(1,2,3) val.rotation = Quaternion(1,2,3,4) return val
def StructureAtom(c_atom, helper): atom = _Atom._create() atom._serial = c_atom.atom_serial atom._occupancy = c_atom.occupancy atom._bfactor = c_atom.bfactor atom._position = Vector3(c_atom.x, c_atom.y, c_atom.z) atom._symbol = c_atom.symbol atom._name = c_atom.atom_name atom._is_het = c_atom.is_het if (atom._symbol == ""): atom._symbol = atom._name[0] if (c_atom.fract and helper != None): helper.Orthogonalize(c_atom.x, c_atom.y, c_atom.z, atom._position) return atom
def create_atom(): val = struct.Atom() val.index = 1000 val.selected = True val.atom_mode = 1 # BALLSTICK val.labeled = True val.atom_rendering = True val.atom_color = Color.White() val.surface_rendering = True val.surface_color = Color.White() val.surface_opacity = 1 val.symbol = "Carbon" val.serial = 0 val.name = "default" val.position = Vector3() return val
def __init__(self, tokens): self.__is_het = tokens[0] != "ATOM" self.__atom_number = int(tokens[1]) self.__atom_name = tokens[2] self.__res_name = tokens[3] if len(tokens) > 10: self.__chain_id = tokens[4] else: self.__chain_id = None # Strip non numeric characters from the residue number res_number = re.sub("[^0-9]", "", tokens[-6]) self.__res_number = int(res_number) self.__position = Vector3(tokens[-5], tokens[-4], tokens[-3]) self.__charge = float(tokens[-2]) self.__radius = float(tokens[-1])
def structure_molecule(atoms, compnds): # All structured infos all_residues = {} #<string, Residue> all_chains = {} #<string, Chain> all_atoms = {} #<string, Atom> # Read all atoms for ratom in atoms: atom = _Atom._create() atom._symbol = ratom.element_symbol atom._serial = ratom.atom_serial_number atom._name = ratom.atom_name #atom.alts = ratom.atom_alternate_location atom._occupancy = ratom.occupancy atom._bfactor = ratom.bfactor #atom.charge = ratom.atom_charge atom._position = Vector3(ratom.atom_x, ratom.atom_y, ratom.atom_z) atom._is_het = ratom.is_het_atom atom_id = ratom.chain_identifier + ":" + str( ratom.residue_serial_number) + ":" + ratom.atom_name + ":" + str( ratom.atom_serial_number) if not atom_id in all_atoms: residue_id = ratom.chain_identifier + ":" + str( ratom.residue_serial_number) + ":" + ratom.segment_identifier if not residue_id in all_residues: residue = _Residue._create() residue._name = ratom.residue_name residue._type = residue._name residue._serial = ratom.residue_serial_number # residue.insertion_code = ratom.residue_insertion_code all_residues[residue_id] = residue chain_id = ratom.chain_identifier if ratom.is_het_atom: chain_id = "H" + chain_id if not chain_id in all_chains: chain = _Chain._create() chain._name = chain_id all_chains[chain_id] = chain all_chains[chain_id]._add_residue(residue) all_residues[residue_id]._add_atom(atom) all_atoms[atom_id] = atom # Final molecule molecule = _Molecule._create() # Assemble molecule contents for chain in all_chains: molecule._add_chain(all_chains[chain]) # Done return molecule
def build_simple_complex(self, name, color): new_complex = Complex() new_complex.name = name new_molecule = Molecule() new_chain = Chain() new_residue = Residue() new_atom1 = Atom() new_atom2 = Atom() new_bond = Bond() new_complex.add_molecule(new_molecule) new_molecule.add_chain(new_chain) new_chain.add_residue(new_residue) new_residue.add_atom(new_atom1) new_residue.add_atom(new_atom2) new_residue.add_bond(new_bond) new_bond.atom1 = new_atom1 new_bond.atom2 = new_atom2 new_atom2.position = Vector3(0, 0, 1) new_atom1.atom_color = color new_atom2.atom_color = color return new_complex
def __init__(self): super(_Complex, self).__init__() #Molecular self._name = "complex" self._index_tag = 0 self._split_tag = "" self._remarks = {} #Rendering self._boxed = False self._locked = False self._visible = True self._computing = False self._current_frame = 0 self._selected = False #selected on live self._surface_dirty = False self._surface_refresh_rate = -1.0 # Not used yet, future auto surface refresh self._box_label = "" #Transform self._position = Vector3(0, 0, 0) self._rotation = Quaternion(0, 0, 0, 0) self._molecules = [] self._parent = None
def __init__(self): super(_Atom, self).__init__() #Molecular self._symbol = "C" self._serial = 1 self._name = "default" self._is_het = False self._atom_type = "C" #No API self._occupancy = 0.0 self._bfactor = 0.0 self._acceptor = False self._donor = False self._formal_charge = 0 #Rendering #API self._selected = False self._atom_mode = _Atom.AtomRenderingMode.BallStick self._labeled = False self._label_text = "" self._atom_rendering = True self._atom_color = Color.Clear() self._atom_scale = 0.5 self._surface_rendering = False self._surface_color = Color.Clear() self._surface_opacity = 1.0 #No API self._hydrogened = True self._watered = True self._het_atomed = True self._het_surfaced = True #conformer self._positions = [Vector3()] self._in_conformer = [True] #internal self._unique_identifier = _Atom._atom_count self._bonds = [] self._parent = None _Atom._atom_count += 1
def parse_lines(lines): descrip = lines[0].split() if(descrip[3] != 'gridpositions'): raise Exception("unsupported OpenDX format {}".format(descrip[3])) dim = [int(x) for x in descrip[-3:]] origin = [float(n) for n in lines[1].split()[1:]] delta = [float(line.split()[i]) for line, i in zip(lines[2:5], range(1, 4))] cell = _UnitCell() cell._A = (dim[0] - 1) * delta[0] cell._B = (dim[1] - 1) * delta[1] cell._C = (dim[2] - 1) * delta[2] cell._Alpha = 90.0 cell._Beta = 90.0 cell._Gamma = 90.0 cell._Origin = Vector3(origin[0], origin[1], origin[2]) volume = _VolumeData() volume._width = dim[0] volume._height = dim[1] volume._depth = dim[2] volume._mean = 0.0 volume._rmsd = 1.0 volume._type = VolumeType.electrostatic volume._name = "map.dx" volume._cell = cell datalines = lines[7:-5] data = [float(x) for line in datalines for x in line.split()] volume._data = [data[z + (y + x * dim[1]) * dim[2]] for z in range(dim[2]) for y in range(dim[1]) for x in range(dim[0])] return volume
def create_workspace(): workspace = struct.Workspace() workspace.complexes = [struct.Complex(), create_complex(), struct.Complex(), create_complex()] workspace.position = Vector3(1,2,3) workspace.rotation = Quaternion(1,2,3,4) return workspace
def test_error_conditions(): sample_kinds = [nanome.util.enums.Kind.CovalentSingle, nanome.util.enums.Kind.CovalentDouble, nanome.util.enums.Kind.CovalentTriple] sample_positions = [Vector3(0,0,0), Vector3(1,1,1), Vector3(2,2,2)] sample_exists = [True, False, True] molecule = create_frames(1)[0] atom = next(molecule.atoms) bond = next(molecule.bonds) failed = False try: atom.positions = sample_positions except ValueError: failed = True assert(failed) failed = False try: atom.in_conformer = sample_exists except ValueError: failed = True assert(failed) failed = False try: bond.in_conformer = sample_exists except ValueError: failed = True assert(failed) failed = False try: bond.kinds = sample_kinds except ValueError: failed = True assert(failed) failed = False try: molecule.associateds = [{}, {}, {}] except ValueError: failed = True assert(failed) failed = False try: molecule.names = ["", "", ""] except ValueError: failed = True assert(failed) new_atom = struct.Atom() new_atom.in_conformer = sample_exists failed = False try: next(molecule.residues).add_atom(new_atom) except ValueError: failed = True assert(failed) new_atom = struct.Atom() new_atom.positions = sample_positions failed = False try: next(molecule.residues).add_atom(new_atom) except ValueError: failed = True assert(failed) new_atom = struct.Atom() new_atom.in_conformer = sample_exists failed = False try: next(molecule.residues).add_atom(new_atom) except ValueError: failed = True assert(failed) new_bond = struct.Bond() new_bond.kinds = sample_kinds failed = False try: next(molecule.residues).add_bond(new_bond) except ValueError: failed = True assert(failed) new_bond = struct.Bond() new_bond.in_conformer = sample_exists failed = False try: next(molecule.residues).add_bond(new_bond) except ValueError: failed = True assert(failed)
def __init__(self): self._position = Vector3() self._rotation = Quaternion() self._scale = Vector3(0.02,0.02,0.02) self._complexes = []
def parse_json(content_json): # type: () -> Button #region text button = _Button._create() button._selected = content_json.read("selected", button._selected) button._unusable = content_json.read("unusable", button._unusable) button._text._active = content_json.read("text_active", button._text._active) button._text._value._idle = content_json.read("text_value_idle", button._text._value._idle) button._text._value._selected = content_json.read( "text_value_selected", button._text._value._selected) button._text._value._highlighted = content_json.read( "text_value_highlighted", button._text._value._highlighted) button._text._value._selected_highlighted = content_json.read( "text_value_selected_highlighted", button._text._value._selected_highlighted) button._text._value._unusable = content_json.read( "text_value_unusable", button._text._value._unusable) button._text._auto_size = content_json.read("text_auto_size", button._text._auto_size) button._text._min_size = content_json.read("text_min_size", button._text._min_size) button._text._max_size = content_json.read("text_max_size", button._text._max_size) button._text._size = content_json.read("text_size", button._text._size) button._text._underlined = content_json.read("text_underlined", button._text._underlined) button._text._bold._set_all(content_json.read("text_bolded", False)) #deprecated button._text._bold._idle = content_json.read("text_bold_idle", button._text._bold._idle) button._text._bold._selected = content_json.read( "text_bold_selected", button._text._bold._selected) button._text._bold._highlighted = content_json.read( "text_bold_highlighted", button._text._bold._highlighted) button._text._bold._selected_highlighted = content_json.read( "text_bold_selected_highlighted", button._text._bold._selected_highlighted) button._text._bold._unusable = content_json.read( "text_bold_unusable", button._text._bold._unusable) button._text._color._idle = content_json.read("text_color_idle", button._text._color._idle) button._text._color._selected = content_json.read( "text_color_selected", button._text._color._selected) button._text._color._highlighted = content_json.read( "text_color_highlighted", button._text._color._highlighted) button._text._color._selected_highlighted = content_json.read( "text_color_selected_highlighted", button._text._color._selected_highlighted) button._text._color._unusable = content_json.read( "text_color_unusable", button._text._color._unusable) button._text._padding_top = content_json.read("text_padding_top", button._text._padding_top) button._text._padding_bottom = content_json.read( "text_padding_bottom", button._text._padding_bottom) button._text._padding_left = content_json.read("text_padding_left", button._text._padding_left) button._text._padding_right = content_json.read( "text_padding_right", button._text._padding_right) button._text._line_spacing = content_json.read("text_line_spacing", button._text._line_spacing) button._text._vertical_align = VertAlignOptions( content_json.read("text_vertical_align", button._text._vertical_align)) button._text._horizontal_align = HorizAlignOptions( content_json.read("text_horizontal_align", button._text._horizontal_align)) #endregion #region icon button._icon._active = content_json.read("icon_active", button._icon._active) button._icon._value._idle = content_json.read("icon_value_idle", button._icon._value._idle) button._icon._value._selected = content_json.read( "icon_value_selected", button._icon._value._selected) button._icon._value._highlighted = content_json.read( "icon_value_highlighted", button._icon._value._highlighted) button._icon._value._selected_highlighted = content_json.read( "icon_value_selected_highlighted", button._icon._value._selected_highlighted) button._icon._value._unusable = content_json.read( "icon_value_unusable", button._icon._value._unusable) button._icon._color._idle = content_json.read("icon_color_idle", button._icon._color._idle) button._icon._color._selected = content_json.read( "icon_color_selected", button._icon._color._selected) button._icon._color._highlighted = content_json.read( "icon_color_highlighted", button._icon._color._highlighted) button._icon._color._selected_highlighted = content_json.read( "icon_color_selected_highlighted", button._icon._color._selected_highlighted) button._icon._color._unusable = content_json.read( "icon_color_unusable", button._icon._color._unusable) button._icon._sharpness = content_json.read("icon_sharpness", button._icon._sharpness) button._icon._size = content_json.read("icon_size", button._icon._size) button._icon._ratio = content_json.read("icon_ratio", button._icon._ratio) button._icon._position = Vector3( content_json.read("icon_position_x", button._icon._position.x), content_json.read("icon_position_y", button._icon._position.y), content_json.read("icon_position_z", button._icon._position.z)) button._icon._rotation = Vector3( content_json.read("icon_rotation_x", button._icon._rotation.x), content_json.read("icon_rotation_y", button._icon._rotation.y), content_json.read("icon_rotation_z", button._icon._rotation.z)) #endregion #region mesh button._mesh._active = content_json.read("mesh_active", button._mesh._active) button._mesh._enabled._idle = content_json.read( "mesh_enabled_idle", button._mesh._enabled._idle) button._mesh._enabled._selected = content_json.read( "mesh_enabled_selected", button._mesh._enabled._selected) button._mesh._enabled._highlighted = content_json.read( "mesh_enabled_highlighted", button._mesh._enabled._highlighted) button._mesh._enabled._selected_highlighted = content_json.read( "mesh_enabled_selected_highlighted", button._mesh._enabled._selected_highlighted) button._mesh._enabled._unusable = content_json.read( "mesh_enabled_unusable", button._mesh._enabled._unusable) button._mesh._color._idle = content_json.read("mesh_color_idle", button._mesh._color._idle) button._mesh._color._selected = content_json.read( "mesh_color_selected", button._mesh._color._selected) button._mesh._color._highlighted = content_json.read( "mesh_color_highlighted", button._mesh._color._highlighted) button._mesh._color._selected_highlighted = content_json.read( "mesh_color_selected_highlighted", button._mesh._color._selected_highlighted) button._mesh._color._unusable = content_json.read( "mesh_color_unusable", button._mesh._color._unusable) #endregion #region outline button._outline._active = content_json.read("outline_active", button._outline._active) button._outline._size._idle = content_json.read( "outline_size_idle", button._outline._size._idle) button._outline._size._selected = content_json.read( "outline_size_selected", button._outline._size._selected) button._outline._size._highlighted = content_json.read( "outline_size_highlighted", button._outline._size._highlighted) button._outline._size._selected_highlighted = content_json.read( "outline_size_selected_highlighted", button._outline._size._selected_highlighted) button._outline._size._unusable = content_json.read( "outline_size_unusable", button._outline._size._unusable) button._outline._color._idle = content_json.read( "outline_color_idle", button._outline._color._idle) button._outline._color._selected = content_json.read( "outline_color_selected", button._outline._color._selected) button._outline._color._highlighted = content_json.read( "outline_color_highlighted", button._outline._color._highlighted) button._outline._color._selected_highlighted = content_json.read( "outline_color_selected_highlighted", button._outline._color._selected_highlighted) button._outline._color._unusable = content_json.read( "outline_color_unusable", button._outline._color._unusable) #endregion #region tooltip button._tooltip._title = content_json.read("tooltip_title", button._tooltip._title) button._tooltip._content = content_json.read("tooltip_content", button._tooltip._content) button._tooltip._bounds = content_json.read("tooltip_bounds", button._tooltip._bounds) button._tooltip._positioning_target = content_json.read( "tooltip_positioning_target", button._tooltip._positioning_target) button._tooltip._positioning_origin = content_json.read( "tooltip_positioning_origin", button._tooltip._positioning_origin) #endregion return button
def convert_to_conformers(complex, force_conformer = None): #Data.Complex -> Data.Complex frame_count = len(complex._molecules) # Maybe conformers are disabled if frame_count <= 1 or s_ConformersDisabled: return complex._deep_copy() # Collect count of first molecule molecule_index = 0 chain_total_count = 0 residue_total_count = 0 atom_total_count = 0 bond_total_count = 0 # Create molecular container new_complex = complex._shallow_copy() #Data.Complex new_complex._current_frame = 0 new_molecule = complex._molecules[0]._shallow_copy() # Data.Molecule # Group structures by their hash new_chains = {} new_residues = {} new_atoms = {} new_bonds = {} # Computation stores sb = StringBuilder() names_dictionary = {} atoms_dictionary = {} # Get ready new_complex._add_molecule(new_molecule) new_molecule._conformer_count = len(complex._molecules) # Loop over all frames for molecule in complex._molecules: # Meta informations new_molecule._names[molecule_index] = molecule._name new_molecule._associateds[molecule_index] = molecule._associated # Loop over all chains for chain in molecule._chains: # Lookup or create chain with hash hash_chain = _get_chain_hash(sb, chain) new_chain = None if hash_chain in new_chains: new_chain = new_chains[hash_chain] else: new_chain = chain._shallow_copy() new_molecule._add_chain(new_chain) new_chains[hash_chain] = new_chain # Loop over all residues for residue in chain._residues: # Lookup or create chain with hash hash_residue = _get_residue_hash(sb, residue) new_residue = None if hash_residue in new_residues: new_residue = new_residues[hash_residue] else: new_residue = residue._shallow_copy() new_chain._add_residue(new_residue) new_residues[hash_residue] = new_residue # Cleanup names_dictionary.clear() for atom in residue._atoms: name_hash = _get_hash_code(atom.name) off = 0 if name_hash in names_dictionary: off = names_dictionary[name_hash] off +=1 names_dictionary[name_hash] = off # Lookup or create atom with hash hash_atom = _get_atom_hash(sb, atom, off) new_atom = None if hash_atom in new_atoms: new_atom = new_atoms[hash_atom] else: new_atom = atom._shallow_copy() new_atom._in_conformer = [False]*new_molecule._conformer_count new_atom._positions = [Vector3()]*new_molecule._conformer_count new_residue._add_atom(new_atom) if off > 1: new_atom.name = new_atom.name + str(off) new_atoms[hash_atom] = new_atom new_atom.serial = len(new_atoms) # Update current conformer new_atom._in_conformer[molecule_index] = True new_atom._positions[molecule_index] = atom.position.get_copy() # Save atoms_dictionary[atom._unique_identifier] = (hash_atom, new_atom) atom_total_count+=1 residue_total_count+=1 chain_total_count+=1 for bond in molecule.bonds: atom_info_1 = atoms_dictionary[bond._atom1._unique_identifier] atom_info_2 = atoms_dictionary[bond._atom2._unique_identifier] # Lookup the parent residue residue = bond._parent hash_residue = _get_residue_hash(sb, residue) new_residue = new_residues[hash_residue] hash_bond = _get_bond_hash(sb, bond, atom_info_1[0], atom_info_2[0]) new_bond = None if hash_bond in new_bonds: new_bond = new_bonds[hash_bond] else: new_bond = bond._shallow_copy() new_bond._in_conformer = [False]*new_molecule._conformer_count new_bond._kinds = [enums.Kind.CovalentSingle]*new_molecule._conformer_count new_residue._add_bond(new_bond) new_bonds[hash_bond] = new_bond # Update current conformer new_bond._in_conformer[molecule_index] = True new_bond._kinds[molecule_index] = bond.kind # Count bonds bond_total_count+=1 for atom in molecule.atoms: for bond in atom.bonds: atom_info_1 = atoms_dictionary[bond._atom1._unique_identifier] atom_info_2 = atoms_dictionary[bond._atom2._unique_identifier] # Lookup the parent residue residue = bond._parent hash_residue = _get_residue_hash(sb, residue) new_residue = new_residues[hash_residue] hash_bond = _get_bond_hash(sb, bond, atom_info_1[0], atom_info_2[0]) new_bond = new_bonds[hash_bond] if atom == bond._atom1: new_bond._atom1 = atom_info_1[1] else: new_bond._atom2 = atom_info_2[1] # Molecule idx molecule_index+=1 if force_conformer == None: force_conformer = s_ConformersAlways # Important decision to make, is everything suited for a trajectories? if not force_conformer: # Gather important information of the conversion is_very_big_chains = chain_total_count > 1 is_very_big_residues = residue_total_count > 10 is_very_big_atoms = atom_total_count > 10000 is_very_big_bonds = bond_total_count > 20000 if len(new_chains) == 0: chain_similarity_ratio = 1 else: chain_similarity_ratio = float(chain_total_count) / float(frame_count) / float(len(new_chains)) if len(new_residues) == 0: residue_similarity_ratio = 1 else: residue_similarity_ratio = float(residue_total_count) / float(frame_count) / float(len(new_residues)) if len(new_atoms) == 0: atom_similarity_ratio = 1 else: atom_similarity_ratio = float(atom_total_count) / float(frame_count) / float(len(new_atoms)) if len(new_bonds) == 0: bond_similarity_ratio = 1 else: bond_similarity_ratio = float(bond_total_count) / float(frame_count) / float(len(new_bonds)) is_chain_similar_enough = chain_similarity_ratio > 0.85 is_residue_similar_enough = residue_similarity_ratio > 0.85 is_atom_similar_enough = atom_similarity_ratio > 0.85 is_bond_similar_enough = bond_similarity_ratio > 0.85 # Cancel conversion if not suited if is_very_big_chains and not is_chain_similar_enough: return complex._deep_copy() if is_very_big_residues and not is_residue_similar_enough: return complex._deep_copy() if is_very_big_atoms and not is_atom_similar_enough: return complex._deep_copy() if is_very_big_bonds and not is_bond_similar_enough: return complex._deep_copy() # Otherwise let's start grabbing the data return new_complex
def deserialize(self, version, context): x = context.read_float() y = context.read_float() z = context.read_float() return Vector3(x, y, z)
def rand_pos(): return Vector3(rand_float(-5, 5), rand_float(0, 2), rand_float(-5, 5))
def rand_scale(): scale = rand_float(.5, 1) return Vector3(scale, scale, scale)
def __init__(self): self._title = "" self._content = "" self._bounds = Vector3(1.73, .6, .05) self._positioning_target = _Button.ToolTipPositioning.right self._positioning_origin = _Button.ToolTipPositioning.top_left
def test_conformer_API(): #test molecule test = create_frames(1)[0] #conformer_count molecule = test._deep_copy() atom = next(molecule.atoms) bond = next(molecule.bonds) molecule.set_current_conformer(1) assert(molecule.current_conformer == 1) assert(atom.current_conformer == 1) assert(bond.current_conformer == 1) assert(molecule.conformer_count == 1) assert(atom.conformer_count == 1) assert(bond.conformer_count == 1) molecule.set_conformer_count(2) assert(molecule.current_conformer == 1) assert(atom.current_conformer == 1) assert(bond.current_conformer == 1) assert(molecule.conformer_count == 2) assert(atom.conformer_count == 2) assert(bond.conformer_count == 2) molecule.set_conformer_count(1) assert(molecule.current_conformer == 0) assert(atom.current_conformer == 0) assert(bond.current_conformer == 0) assert(molecule.conformer_count == 1) assert(atom.conformer_count == 1) assert(bond.conformer_count == 1) #list_resizing molecule = test._deep_copy() atom = next(molecule.atoms) bond = next(molecule.bonds) molecule.set_conformer_count(2) assert(len(molecule.names) == 2) assert(len(molecule.associateds) == 2) assert(molecule.names[1] == molecule.names[0]) assert(molecule.associateds[1] == molecule.associateds[0]) assert(len(atom.positions) == 2) assert(len(atom.in_conformer) == 2) assert(atom.positions[1].equals(atom.positions[0])) assert(atom.in_conformer[1] == atom.in_conformer[0]) assert(len(bond.kinds) == 2) assert(len(bond.in_conformer) == 2) assert(bond.kinds[1] == bond.kinds[0]) assert(bond.in_conformer[1] == bond.in_conformer[0]) #convenience functions reference = test._deep_copy() atom = next(reference.atoms) bond = next(reference.bonds) reference.set_conformer_count(3) atom.positions = [Vector3(0,0,0), Vector3(1,1,1), Vector3(2,2,2)] bond.kinds = [nanome.util.enums.Kind.CovalentSingle, nanome.util.enums.Kind.CovalentDouble, nanome.util.enums.Kind.CovalentTriple] molecule = reference._deep_copy() atom = next(molecule.atoms) molecule.create_conformer(1) assert(molecule.conformer_count == 4) assert(len(molecule.names) == 4) assert(len(atom.positions) == 4) assert(atom.positions[0].equals(atom.positions[1])) assert(atom.positions[0] != atom.positions[1]) molecule.create_conformer(4) molecule.create_conformer(0) molecule = reference._deep_copy() bond = next(molecule.bonds) molecule.copy_conformer(2, 0) assert(molecule.conformer_count == 4) assert(len(molecule.names) == 4) assert(len(bond.kinds) == 4) assert(bond.kinds[0] == bond.kinds[3]) molecule.copy_conformer(3) molecule.copy_conformer(0) molecule = reference._deep_copy() bond = next(molecule.bonds) atom = next(molecule.atoms) position = atom.positions[2] molecule.move_conformer(2, 0) assert(molecule.conformer_count == 3) assert(len(molecule.names) == 3) assert(len(atom.positions) == 3) assert(atom.position[2] != position) assert(position == atom.positions[0]) molecule.move_conformer(2,2) molecule.move_conformer(0,0) molecule.move_conformer(0,3) molecule = reference._deep_copy() bond = next(molecule.bonds) atom = next(molecule.atoms) molecule.set_current_conformer(2) position = atom.positions[2] deleted = atom.positions[0] molecule.delete_conformer(0) assert(molecule.current_conformer == 1) assert(molecule.conformer_count == 2) assert(len(molecule.names) == 2) assert(len(atom.positions) == 2) assert(atom.positions[1] == position) assert(atom.positions[0] != deleted) molecule.delete_conformer(1) molecule.delete_conformer(0)