diff --git a/molsysmt/_private/digestion/argument/copy_if_None.py b/molsysmt/_private/digestion/argument/copy_if_None.py new file mode 100644 index 000000000..9576cae60 --- /dev/null +++ b/molsysmt/_private/digestion/argument/copy_if_None.py @@ -0,0 +1,9 @@ +from molsysmt._private.exceptions import ArgumentError + +def digest_copy_if_None(copy_if_None, caller=None): + + if isinstance(copy_if_None, bool): + return copy_if_None + + raise ArgumentError('copy_if_None', value=copy_if_None, caller=caller, message=None) + diff --git a/molsysmt/_private/digestion/argument/n_atoms.py b/molsysmt/_private/digestion/argument/n_atoms.py index 9b2a2a715..82df98bcb 100644 --- a/molsysmt/_private/digestion/argument/n_atoms.py +++ b/molsysmt/_private/digestion/argument/n_atoms.py @@ -22,6 +22,9 @@ def digest_n_atoms(n_atoms, caller=None): elif caller=='molsysmt.native.topology.__init__': if isinstance(n_atoms, int): return n_atoms + elif caller=='molsysmt.native.molsys.__init__': + if isinstance(n_atoms, int): + return n_atoms raise ArgumentError('n_atoms', value=n_atoms, caller=caller, message=None) diff --git a/molsysmt/_private/digestion/argument/n_bonds.py b/molsysmt/_private/digestion/argument/n_bonds.py index fcb37e544..28fe429c8 100644 --- a/molsysmt/_private/digestion/argument/n_bonds.py +++ b/molsysmt/_private/digestion/argument/n_bonds.py @@ -11,5 +11,8 @@ def digest_n_bonds(n_bonds, caller=None): elif caller=='molsysmt.native.topology.__init__': if isinstance(n_bonds, int): return n_bonds + elif caller=='molsysmt.native.molsys.__init__': + if isinstance(n_bonds, int): + return n_bonds raise ArgumentError('n_entities', value=n_entities, caller=caller, message=None) diff --git a/molsysmt/_private/digestion/argument/n_chains.py b/molsysmt/_private/digestion/argument/n_chains.py index 38479ac3e..64ea2c011 100644 --- a/molsysmt/_private/digestion/argument/n_chains.py +++ b/molsysmt/_private/digestion/argument/n_chains.py @@ -22,6 +22,9 @@ def digest_n_chains(n_chains, caller=None): elif caller=='molsysmt.native.topology.__init__': if isinstance(n_chains, int): return n_chains + elif caller=='molsysmt.native.molsys.__init__': + if isinstance(n_chains, int): + return n_chains raise ArgumentError('n_chains', value=n_chains, caller=caller, message=None) diff --git a/molsysmt/_private/digestion/argument/n_components.py b/molsysmt/_private/digestion/argument/n_components.py index 9979fe5d2..e29a26bec 100644 --- a/molsysmt/_private/digestion/argument/n_components.py +++ b/molsysmt/_private/digestion/argument/n_components.py @@ -22,6 +22,9 @@ def digest_n_components(n_components, caller=None): elif caller=='molsysmt.native.topology.__init__': if isinstance(n_components, int): return n_components + elif caller=='molsysmt.native.molsys.__init__': + if isinstance(n_components, int): + return n_components raise ArgumentError('n_components', value=n_components, caller=caller, message=None) diff --git a/molsysmt/_private/digestion/argument/n_entities.py b/molsysmt/_private/digestion/argument/n_entities.py index 17c4b6755..66da95bb5 100644 --- a/molsysmt/_private/digestion/argument/n_entities.py +++ b/molsysmt/_private/digestion/argument/n_entities.py @@ -22,6 +22,9 @@ def digest_n_entities(n_entities, caller=None): elif caller=='molsysmt.native.topology.__init__': if isinstance(n_entities, int): return n_entities + elif caller=='molsysmt.native.molsys.__init__': + if isinstance(n_entities, int): + return n_entities raise ArgumentError('n_entities', value=n_entities, caller=caller, message=None) diff --git a/molsysmt/_private/digestion/argument/n_groups.py b/molsysmt/_private/digestion/argument/n_groups.py index 803ad7baf..2910a0512 100644 --- a/molsysmt/_private/digestion/argument/n_groups.py +++ b/molsysmt/_private/digestion/argument/n_groups.py @@ -22,6 +22,9 @@ def digest_n_groups(n_groups, caller=None): elif caller=='molsysmt.native.topology.__init__': if isinstance(n_groups, int): return n_groups + elif caller=='molsysmt.native.molsys.__init__': + if isinstance(n_groups, int): + return n_groups raise ArgumentError('n_groups', value=n_groups, caller=caller, message=None) diff --git a/molsysmt/_private/digestion/argument/n_molecules.py b/molsysmt/_private/digestion/argument/n_molecules.py index 48bf94116..34145f35d 100644 --- a/molsysmt/_private/digestion/argument/n_molecules.py +++ b/molsysmt/_private/digestion/argument/n_molecules.py @@ -22,6 +22,9 @@ def digest_n_molecules(n_molecules, caller=None): elif caller=='molsysmt.native.topology.__init__': if isinstance(n_molecules, int): return n_molecules + elif caller=='molsysmt.native.molsys.__init__': + if isinstance(n_molecules, int): + return n_molecules raise ArgumentError('n_molecules', value=n_molecules, caller=caller, message=None) diff --git a/molsysmt/element/group/__init__.py b/molsysmt/element/group/__init__.py index ed234078d..569a4f23b 100644 --- a/molsysmt/element/group/__init__.py +++ b/molsysmt/element/group/__init__.py @@ -10,6 +10,7 @@ from .is_group_type import is_group_type from .get_group_type import get_group_type, get_group_type_from_group_name +from .get_bonded_atom_pairs import get_bonded_atom_pairs _group_types = [ 'water', diff --git a/molsysmt/element/group/get_bonded_atom_pairs.py b/molsysmt/element/group/get_bonded_atom_pairs.py new file mode 100644 index 000000000..6226788f4 --- /dev/null +++ b/molsysmt/element/group/get_bonded_atom_pairs.py @@ -0,0 +1,54 @@ +import numpy as np + +def get_bonded_atom_pairs(group_name, atom_names, atom_indices=None, sorted=True): + + from .get_group_type import get_group_type_from_group_name + from amino_acid import get_bonded_atom_pairs as get_bonded_atom_pairs_from_amino_acid + from ion import get_bonded_atom_pairs as get_bonded_atom_pairs_from_ion + from small_molecule import get_bonded_atom_pairs as get_bonded_atom_pairs_from_small_molecule + from terminal_capping import get_bonded_atom_pairs as get_bonded_atom_pairs_from_terminal_capping + from water import get_bonded_atom_pairs as get_bonded_atom_pairs_from_water + + group_type = get_group_type_from_group_name(group_name) + + bonds = None + + match group_type: + + case 'amino acid': + bonds = get_bonded_atom_pairs_from_amino_acid(group_name, atom_names, atom_indices=atom_indices, + sorted=sorted) + + case 'ion': + bonds = get_bonded_atom_pairs_from_ion(group_name, atom_names, atom_indices=atom_indices, sorted=sorted) + + case 'lipid': + pass + + case 'nucleotide': + pass + + case 'oligosaccharide': + pass + + case 'saccharide': + pass + + case 'small molecule': + bonds = get_bonded_atom_pairs_from_small_molecule(group_name, atom_names, atom_indices=atom_indices, + sorted=sorted) + + case 'terminal capping': + bonds = get_bonded_atom_pairs_from_terminal_capping(group_name, atom_names, atom_indices=atom_indices, + sorted=sorted) + + case 'water': + bonds = get_bonded_atom_pairs_from_water(atom_names, atom_indices=atom_indices, sorted=sorted) + + + if bonds is None: + print(f'Warning! The amino acid {group_name} has no template.') + raise ValueError + + return bonds + diff --git a/molsysmt/form/mmtf_MMTFDecoder/to_molsysmt_MolSys.py b/molsysmt/form/mmtf_MMTFDecoder/to_molsysmt_MolSys.py index ac3299f29..0626c07ee 100644 --- a/molsysmt/form/mmtf_MMTFDecoder/to_molsysmt_MolSys.py +++ b/molsysmt/form/mmtf_MMTFDecoder/to_molsysmt_MolSys.py @@ -9,8 +9,8 @@ @digest(form='mmtf.MMTFDecoder') def to_molsysmt_MolSys(item, atom_indices='all', structure_indices='all', skip_digestion=False): - import warnings from molsysmt.native import MolSys + from molsysmt.config import min_length_protein # atoms, groups and bonds intra group @@ -34,8 +34,6 @@ def to_molsysmt_MolSys(item, atom_indices='all', structure_indices='all', skip_d bond_atom1_index_array = np.empty(n_bonds, dtype=int) bond_atom2_index_array = np.empty(n_bonds, dtype=int) - bond_type_array = np.empty(n_bonds, dtype=object) - bond_order_array = np.empty(n_bonds, dtype=int) formal_charge_array = np.empty(n_atoms, dtype=float) @@ -50,12 +48,21 @@ def to_molsysmt_MolSys(item, atom_indices='all', structure_indices='all', skip_d # bonds intra-groups - for bond_pair, bond_order in zip(np.reshape(mmtf_group['bondAtomList'],(-1,2)), mmtf_group['bondOrderList']): + if len(np.unique(mmtf_group['bondAtomList']))==len(mmtf_group['atomNameList']): + + for bond_pair in np.reshape(mmtf_group['bondAtomList'],(-1,2)): + + bond_atom1_index_array[bond_index]=bond_pair[0]+atom_index + bond_atom2_index_array[bond_index]=bond_pair[1]+atom_index + bond_index+=1 + + else: + + aux_bonds = get_bonded_atom_pairs(mmtf_group['groupName'], mmtf_group['atomNameList']) + + print(aux_bonds) + print('error', mmtf_group['groupName']) - bond_atom1_index_array[bond_index]=bond_pair[0]+atom_index - bond_atom2_index_array[bond_index]=bond_pair[1]+atom_index - bond_order_array[bond_index]=bond_order - bond_index+=1 for atom_name, atom_type, atom_formal_charge in zip(mmtf_group['atomNameList'], mmtf_group['elementList'], mmtf_group['formalChargeList']): @@ -73,7 +80,7 @@ def to_molsysmt_MolSys(item, atom_indices='all', structure_indices='all', skip_d for bond_pair, bond_order in zip(np.reshape(item.bond_atom_list,(-1,2)), item.bond_order_list): bond_atom1_index_array[bond_index]=bond_pair[0] bond_atom2_index_array[bond_index]=bond_pair[1] - bond_order_array[bond_index]=bond_order + #bond_order_array[bond_index]=bond_order bond_index+=1 # chains @@ -150,6 +157,8 @@ def to_molsysmt_MolSys(item, atom_indices='all', structure_indices='all', skip_d if len(alt_atom_indices): + print('>@>',alt_atom_indices) + alt_atom_names = atom_name[alt_atom_indices] alt_group_ids = group_id[alt_atom_indices] alt_chain_ids = chain_id[alt_atom_indices] @@ -174,11 +183,12 @@ def to_molsysmt_MolSys(item, atom_indices='all', structure_indices='all', skip_d chosen_with_alt_loc.append(chosen) atoms_to_be_removed_with_alt_loc += [ii for ii in same_atoms if ii !=chosen] - atom_indices_to_be_kept = list(set(np.arange(n_atoms))-set(atoms_to_be_removed_with_alt_loc)) + atom_indices_to_be_kept = np.setdiff1(np.arange(n_atoms), atoms_to_be_removed_with_alt_loc) + dict_old_to_new_atom_indices = {jj: ii for ii, jj in enumerate(atom_indices_to_be_kept)} aux_alternate_location = [{}] for chosen, same_atoms in zip(chosen_with_alt_loc, aux_dict.values()): - atom_index = np.where(atom_indices_to_be_kept==chosen)[0][0] + atom_index = dict_old_to_new_atom_indices[chosen] aux_dict={ 'location_id':alternate_location[same_atoms], 'occupancy':occupancy[same_atoms], @@ -188,77 +198,62 @@ def to_molsysmt_MolSys(item, atom_indices='all', structure_indices='all', skip_d } aux_alternate_location[0][atom_index]=aux_dict - atom_name_array = np.empty(n_atoms, dtype=object) - atom_id_array = np.empty(n_atoms, dtype=int) - atom_type_array = np.empty(n_atoms, dtype=object) - group_index_array = np.empty(n_atoms, dtype=int) - chain_index_array = np.empty(n_atoms, dtype=int) - - - bond_atom1_index_array = np.empty(n_bonds, dtype=int) - bond_atom2_index_array = np.empty(n_bonds, dtype=int) - bond_type_array = np.empty(n_bonds, dtype=object) - bond_order_array = np.empty(n_bonds, dtype=int) - - formal_charge_array = np.empty(n_atoms, dtype=float) - + atom_name_array = atom_name_array[atom_indices_to_be_kept] + atom_id_array = atom_id_array[atom_indices_to_be_kept] + atom_type_array = atom_type_array[atom_indices_to_be_kept] + group_index_array = group_index_array[atom_indices_to_be_kept] + chain_index_array = chain_index_array[atom_indices_to_be_kept] + + mask1 = np.isin(bond_atom1_index_array, atom_indices_to_be_kept) + mask2 = np.isin(bond_atom2_index_array, atom_indices_to_be_kept) + mask = mask1*mask2 + + vaux_dict = np.vectorize(dict_old_to_new_atom_indices.__getitem__) + bond_atom1_index_array = bond_atom1_index_array[mask] + bond_atom1_index_array = vaux_dict(bond_atom1_index_array) + bond_atom2_index_array = bond_atom2_index_array[mask] + bond_atom2_index_array = vaux_dict(bond_atom2_index_array) + #bond_type_array = bond_type_array[mask] + #bond_order_array = bond_order_array[mask] + coordinates = coordinates[:,atom_indices_to_be_kept,:] b_factor = b_factor[atom_indices_to_be_kept] + formal_charge_array = formal_charge_array[atom_indices_to_be_kept] alternate_location = aux_alternate_location + n_atoms=atom_name_array.shape[0] + n_bonds= bond_atom1_index_array.shape[0] - - - - - - - + tmp_item = MolSys(n_atoms=n_atoms, n_groups=n_groups, n_chains=n_chains, n_bonds=n_bonds) tmp_item.topology.atoms["atom_name"] = atom_name_array tmp_item.topology.atoms["atom_id"] = atom_id_array tmp_item.topology.atoms["atom_type"] = atom_type_array tmp_item.topology.atoms["group_index"] = group_index_array - del(atom_name_array, atom_id_array, atom_type_array, group_index_array) - - #tmp_item.atoms_dataframe["occupancy"] = item.occupancy_list - - #tmp_item.atoms_dataframe["alternate_location"] = np.array(item.alt_loc_list) - #tmp_item.atoms_dataframe["alternate_location"].replace({'':None}, inplace=True) + tmp_item.topology.atoms["chain_index"] = chain_index_array + del(atom_name_array, atom_id_array, atom_type_array, group_index_array, chain_index_array) tmp_item.topology.groups["group_name"] = group_name_array tmp_item.topology.groups["group_id"] = group_id_array - tmp_item.topology.groups["group_type"] = group_type_array - del(group_name_array, group_id_array, group_type_array) - tmp_item.topology.rebuild_groups(redefine_ids=False, redefine_types=True) + del(group_name_array, group_id_array) - #b_factor_array = puw.quantity(np.array(item.b_factor_list), unit='angstroms**2', standardized=True) - #tmp_item.atoms_dataframe["b_factor"] = puw.get_value(b_factor_array) - - #formal_charge_array = puw.quantity(formal_charge_array, unit='e', standardized=True) - #tmp_item.atoms_dataframe["formal_charge"] = puw.get_value(formal_charge_array) - #del(formal_charge_array, b_factor_array) - - #### bonds + tmp_item.topology.chains["chain_name"] = chain_name_array + tmp_item.topology.chains["chain_id"] = chain_id_array + del(chain_name_array, chain_id_array) tmp_item.topology.bonds["atom1_index"] = bond_atom1_index_array tmp_item.topology.bonds["atom2_index"] = bond_atom2_index_array - #tmp_item.bonds["order"] = bond_order_array - del(bond_atom1_index_array, bond_atom2_index_array) #bond_order_array) + #tmp_item.topology.bonds["order"] = bond_order_array + tmp_item.topology.bonds._remove_empty_columns() tmp_item.topology.bonds._sort_bonds() + del(bond_atom1_index_array, bond_atom2_index_array) - #### chains - - tmp_item.topology.atoms["chain_index"] = chain_index_array - tmp_item.topology.chains["chain_name"] = chain_name_array - tmp_item.topology.chains["chain_id"] = chain_id_array - - del(chain_index_array, chain_name_array, chain_id_array) - - # components + tmp_item.topology.rebuild_groups(redefine_ids=False, redefine_types=True) tmp_item.topology.rebuild_components(redefine_indices=True, redefine_ids=True, - redefine_names=False, redefine_types=False) + redefine_names=False, redefine_types=True) + + return tmp_item molecule_index = 0 @@ -349,7 +344,7 @@ def to_molsysmt_MolSys(item, atom_indices='all', structure_indices='all', skip_d elif first_group_type == 'nucleotide': - pass + raise ValueError("Entity type not recognized:", first_group_type) else: @@ -370,66 +365,12 @@ def to_molsysmt_MolSys(item, atom_indices='all', structure_indices='all', skip_d tmp_item.topology.rebuild_entities(redefine_indices=True, redefine_ids=True, redefine_names=True, redefine_types=True) - ## nan to None - - #tmp_item._nan_to_None() - - - ## If atoms with alternate location the highest occupancy or A is taken - ## other pseudo-atoms are removed - - occupancy = np.array(item.occupancy_list) - alternate_location = np.array(item.alt_loc_list) - b_factor = puw.quantity(np.array(item.b_factor_list), unit='angstroms**2', standardized=True) - alt_atom_indices = np.where(alternate_location!='')[0] - - alt_atoms_dict = [] - atoms_to_be_removed_with_alt_loc = [] - - if len(alt_atom_indices): - - if item.num_models>1: - raise ValueError('Error: multiple models with alternate location.') - - alt_atom_names = tmp_item.topology.atoms["atom_name"][alt_atom_indices].to_numpy() - alt_group_index = tmp_item.topology.atoms["group_index"][alt_atom_indices].to_numpy() - alt_chain_index = tmp_item.topology.atoms["chain_index"][alt_atom_indices].to_numpy() - - aux_dict = {} - - for aux_atom_index, aux_atom_name, aux_group_index, aux_chain_index in zip(alt_atom_indices, - alt_atom_names, alt_group_index, - alt_chain_index): - aux_key = tuple([aux_atom_name, aux_group_index, aux_chain_index]) - if aux_key in aux_dict: - aux_dict[aux_key].append(aux_atom_index) - else: - aux_dict[aux_key]=[aux_atom_index] - - aux_atoms_to_be_removed=[] - chosen_with_alt_loc = [] - for same_atoms in aux_dict.values(): - alt_occupancy = occupancy[same_atoms] - alt_loc = alternate_location[same_atoms] - if np.allclose(alt_occupancy, alt_occupancy[0]): - chosen = np.where(alt_loc=='A')[0][0] - else: - chosen = np.argmax(alt_occupancy) - chosen = same_atoms.pop(chosen) - aux_atoms_to_be_removed += same_atoms - - alt_atoms_dict.append(aux_dict) - - atom_id_array = np.delete(atom_id_array, aux_atoms_to_be_removed) - atom_name_array = np.delete(atom_name_array, aux_atoms_to_be_removed) - group_index_array = np.delete(group_index_array, aux_atoms_to_be_removed) - chain_index_array = np.delete(chain_index_array, aux_atoms_to_be_removed) - coordinates_array[0] = np.delete(coordinates_array[0], aux_atoms_to_be_removed) + # structures - tmp_item = tmp_item.extract(atom_indices=atom_indices, structure_indices=structure_indices, - copy_if_all=False, skip_digestion=True) + tmp_item.structures.append(coordinates=coordinates, box=box) - #No siempre está + #tmp_item = tmp_item.extract(atom_indices=atom_indices, structure_indices=structure_indices, + # copy_if_all=False, skip_digestion=True) return tmp_item diff --git a/molsysmt/native/molsys.py b/molsysmt/native/molsys.py index a9c34f550..84933c76d 100644 --- a/molsysmt/native/molsys.py +++ b/molsysmt/native/molsys.py @@ -31,13 +31,42 @@ def extract(self, atom_indices='all', structure_indices='all', copy_if_all=True, else: tmp_item = MolSys() - tmp_item.topology = self.topology.extract(atom_indices=atom_indices, skip_digestion=True) + tmp_item.topology = self.topology.extract(atom_indices=atom_indices, copy_if_all=True,skip_digestion=True) tmp_item.structures = self.structures.extract(atom_indices=atom_indices, - structure_indices=structure_indices, skip_digestion=True) + structure_indices=structure_indices, copy_if_all=True, + skip_digestion=True) tmp_item.molecular_mechanics = self.molecular_mechanics.copy() return tmp_item + + @digest() + def remove(self, atom_indices=None, structure_indices=None, copy_if_None=False, skip_digestion=False): + + if (atom_indices is None) and (structure_indices is None): + + if copy_if_None: + return self.copy() + else: + return self + + else: + + if atom_indices is not None: + atom_indices_to_be_kept = np.setdiff1d(np.arange(self.topology.n_atoms), atom_indices) + else: + atom_indices_to_be_kept = 'all' + + if structure_indices is not None: + structure_indices_to_be_kept = np.setdiff1d(np.arange(self.structures.n_structures), structure_indices) + else: + structure_indices_to_be_kept = 'all' + + tmp_item = self.extract(atom_indices=atom_indices_to_be_kept, + structure_indices=structure_indices_to_be_kept, skip_digestion=True) + + return tmp_item + @digest(form='molsysmt.MolSys') def add(self, item, atom_indices='all', structure_indices='all', keep_ids=True, skip_digestion=False): diff --git a/molsysmt/native/topology.py b/molsysmt/native/topology.py index 2dcaa17c0..a2edf6988 100644 --- a/molsysmt/native/topology.py +++ b/molsysmt/native/topology.py @@ -268,6 +268,25 @@ def extract(self, atom_indices='all', copy_if_all=False, skip_digestion=False): return tmp_item + @digest() + def remove(self, atom_indices=None, copy_if_None=False, skip_digestion=False): + + if atom_indices is None: + + if copy_if_None: + return self.copy() + else: + return self + + else: + + atom_indices_to_be_kept = np.setdiff1d(np.arange(self.n_atoms), atom_indices) + + tmp_item = self.extract(atom_indices=atom_indices_to_be_kept, skip_digestion=True) + + return tmp_item + + @digest(form='molsysmt.Topology') def add(self, item, atom_indices='all', keep_ids=True, skip_digestion=False): diff --git a/sandbox/Tests.ipynb b/sandbox/Tests.ipynb index d6b2015fa..03ef38749 100644 --- a/sandbox/Tests.ipynb +++ b/sandbox/Tests.ipynb @@ -28,7 +28,7 @@ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "19cd75824e8c421487894509d9ba7acf", + "model_id": "52e1025b948741e5be432764edf7c126", "version_major": 2, "version_minor": 0 }, @@ -55,7 +55,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 4, "id": "6a3ac47f-9953-48b8-8ab4-3610761455a0", "metadata": {}, "outputs": [], @@ -65,7 +65,66 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 5, + "id": "4c1c18ff-c441-4dba-bb81-64e848df8f4d", + "metadata": {}, + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'get_bonded_atom_pairs' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[5], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m molsys \u001b[38;5;241m=\u001b[39m \u001b[43mmsm\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mconvert\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mpdb_id:1l2y\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/repos@uibcdf/MolSysMT/molsysmt/_private/digestion/digest.py:122\u001b[0m, in \u001b[0;36mdigest..digestor..wrapper\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 120\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m func(all_args[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mself\u001b[39m\u001b[38;5;124m'\u001b[39m], \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mfinal_args)\n\u001b[1;32m 121\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m--> 122\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mfinal_args\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[0;32m~/repos@uibcdf/MolSysMT/molsysmt/basic/convert.py:530\u001b[0m, in \u001b[0;36mconvert\u001b[0;34m(molecular_system, to_form, selection, structure_indices, syntax, verbose, skip_digestion, **kwargs)\u001b[0m\n\u001b[1;32m 528\u001b[0m \u001b[38;5;66;03m# If one to one\u001b[39;00m\n\u001b[1;32m 529\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(from_form, (\u001b[38;5;28mlist\u001b[39m, \u001b[38;5;28mtuple\u001b[39m)):\n\u001b[0;32m--> 530\u001b[0m output \u001b[38;5;241m=\u001b[39m \u001b[43m_convert_one_to_one\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmolecular_system\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mfrom_form\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mto_form\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mto_form\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mselection\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mselection\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mstructure_indices\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstructure_indices\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 531\u001b[0m \u001b[43m \u001b[49m\u001b[43msyntax\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43msyntax\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mverbose\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mverbose\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mskip_digestion\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 533\u001b[0m \u001b[38;5;66;03m# If multiple to one\u001b[39;00m\n\u001b[1;32m 534\u001b[0m \n\u001b[1;32m 535\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[1;32m 536\u001b[0m \n\u001b[1;32m 537\u001b[0m \u001b[38;5;66;03m# conversions in private shortcuts\u001b[39;00m\n\u001b[1;32m 538\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mtuple\u001b[39m(\u001b[38;5;28msorted\u001b[39m(from_form)) \u001b[38;5;129;01min\u001b[39;00m _multiple_conversion_shortcuts:\n", + "File \u001b[0;32m~/repos@uibcdf/MolSysMT/molsysmt/basic/convert.py:87\u001b[0m, in \u001b[0;36m_convert_one_to_one\u001b[0;34m(molecular_system, from_form, to_form, selection, structure_indices, syntax, verbose, **kwargs)\u001b[0m\n\u001b[1;32m 84\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;28mlen\u001b[39m(missing_arguments)\u001b[38;5;241m>\u001b[39m\u001b[38;5;241m0\u001b[39m:\n\u001b[1;32m 85\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m NotCompatibleConversionError(from_form, to_form, missing_arguments)\n\u001b[0;32m---> 87\u001b[0m output \u001b[38;5;241m=\u001b[39m \u001b[43mfunction\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmolecular_system\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mconversion_arguments\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 89\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m (\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmolsysmt.MolSys\u001b[39m\u001b[38;5;124m'\u001b[39m \u001b[38;5;129;01min\u001b[39;00m _dict_modules[from_form]\u001b[38;5;241m.\u001b[39m_convert_to) \u001b[38;5;129;01mand\u001b[39;00m (to_form \u001b[38;5;129;01min\u001b[39;00m _dict_modules[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmolsysmt.MolSys\u001b[39m\u001b[38;5;124m'\u001b[39m]\u001b[38;5;241m.\u001b[39m_convert_to):\n\u001b[1;32m 91\u001b[0m output \u001b[38;5;241m=\u001b[39m _convert_one_to_one(molecular_system, from_form, to_form\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmolsysmt.MolSys\u001b[39m\u001b[38;5;124m'\u001b[39m, selection\u001b[38;5;241m=\u001b[39mselection,\n\u001b[1;32m 92\u001b[0m structure_indices\u001b[38;5;241m=\u001b[39mstructure_indices, syntax\u001b[38;5;241m=\u001b[39msyntax, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\n", + "File \u001b[0;32m~/repos@uibcdf/MolSysMT/molsysmt/_private/digestion/digest.py:52\u001b[0m, in \u001b[0;36mdigest..digestor..wrapper\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 48\u001b[0m \u001b[38;5;129m@functools\u001b[39m\u001b[38;5;241m.\u001b[39mwraps(func)\n\u001b[1;32m 49\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mwrapper\u001b[39m(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[1;32m 51\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m kwargs\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mskip_digestion\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;28;01mFalse\u001b[39;00m):\n\u001b[0;32m---> 52\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 54\u001b[0m \u001b[38;5;66;03m# Define caller\u001b[39;00m\n\u001b[1;32m 56\u001b[0m caller \u001b[38;5;241m=\u001b[39m func\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__module__\u001b[39m\u001b[38;5;241m+\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m.\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;241m+\u001b[39mfunc\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m\n", + "File \u001b[0;32m~/repos@uibcdf/MolSysMT/molsysmt/form/string_pdb_id/to_molsysmt_MolSys.py:10\u001b[0m, in \u001b[0;36mto_molsysmt_MolSys\u001b[0;34m(item, atom_indices, structure_indices, skip_digestion)\u001b[0m\n\u001b[1;32m 7\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mmmtf_MMTFDecoder\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m to_molsysmt_MolSys \u001b[38;5;28;01mas\u001b[39;00m mmtf_MMTFDecoder_to_molsysmt_MolSys\n\u001b[1;32m 9\u001b[0m tmp_item \u001b[38;5;241m=\u001b[39m to_mmtf_MMTFDecoder(item, skip_digestion\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[0;32m---> 10\u001b[0m tmp_item \u001b[38;5;241m=\u001b[39m \u001b[43mmmtf_MMTFDecoder_to_molsysmt_MolSys\u001b[49m\u001b[43m(\u001b[49m\u001b[43mtmp_item\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43matom_indices\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43matom_indices\u001b[49m\u001b[43m,\u001b[49m\n\u001b[1;32m 11\u001b[0m \u001b[43m \u001b[49m\u001b[43mstructure_indices\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mstructure_indices\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mskip_digestion\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mTrue\u001b[39;49;00m\u001b[43m)\u001b[49m\n\u001b[1;32m 12\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m tmp_item\n", + "File \u001b[0;32m~/repos@uibcdf/MolSysMT/molsysmt/_private/digestion/digest.py:52\u001b[0m, in \u001b[0;36mdigest..digestor..wrapper\u001b[0;34m(*args, **kwargs)\u001b[0m\n\u001b[1;32m 48\u001b[0m \u001b[38;5;129m@functools\u001b[39m\u001b[38;5;241m.\u001b[39mwraps(func)\n\u001b[1;32m 49\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mwrapper\u001b[39m(\u001b[38;5;241m*\u001b[39margs, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs):\n\u001b[1;32m 51\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m kwargs\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mskip_digestion\u001b[39m\u001b[38;5;124m'\u001b[39m, \u001b[38;5;28;01mFalse\u001b[39;00m):\n\u001b[0;32m---> 52\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mfunc\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 54\u001b[0m \u001b[38;5;66;03m# Define caller\u001b[39;00m\n\u001b[1;32m 56\u001b[0m caller \u001b[38;5;241m=\u001b[39m func\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__module__\u001b[39m\u001b[38;5;241m+\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m.\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;241m+\u001b[39mfunc\u001b[38;5;241m.\u001b[39m\u001b[38;5;18m__name__\u001b[39m\n", + "File \u001b[0;32m~/repos@uibcdf/MolSysMT/molsysmt/form/mmtf_MMTFDecoder/to_molsysmt_MolSys.py:61\u001b[0m, in \u001b[0;36mto_molsysmt_MolSys\u001b[0;34m(item, atom_indices, structure_indices, skip_digestion)\u001b[0m\n\u001b[1;32m 57\u001b[0m bond_index\u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m\u001b[38;5;241m1\u001b[39m\n\u001b[1;32m 59\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m---> 61\u001b[0m aux_bonds \u001b[38;5;241m=\u001b[39m \u001b[43mget_bonded_atom_pairs\u001b[49m(mmtf_group[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mgroupName\u001b[39m\u001b[38;5;124m'\u001b[39m], mmtf_group[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124matomNameList\u001b[39m\u001b[38;5;124m'\u001b[39m])\n\u001b[1;32m 63\u001b[0m \u001b[38;5;28mprint\u001b[39m(aux_bonds)\n\u001b[1;32m 64\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124merror\u001b[39m\u001b[38;5;124m'\u001b[39m, mmtf_group[\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mgroupName\u001b[39m\u001b[38;5;124m'\u001b[39m])\n", + "\u001b[0;31mNameError\u001b[0m: name 'get_bonded_atom_pairs' is not defined" + ] + } + ], + "source": [ + "molsys = msm.convert('pdb_id:1l2y')" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "3b2d88ae-1213-4ed4-b18e-ee614efd72e9", + "metadata": {}, + "outputs": [], + "source": [ + "molsys.topology.bonds" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "8ebcf6d8-2623-487f-b158-01a6122e9103", + "metadata": {}, + "outputs": [], + "source": [ + "38*20" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4f7ec4e4-8d3f-4371-a633-5b3e1e21a56d", + "metadata": {}, + "outputs": [], + "source": [ + "molsys.topology.groups[:30]" + ] + }, + { + "cell_type": "code", + "execution_count": null, "id": "031d1ebc-3c34-44ea-a6f2-524e8971ec30", "metadata": {}, "outputs": [], @@ -75,7 +134,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": null, "id": "30beb7bd-36fd-49b6-b281-5a69e45de3a4", "metadata": {}, "outputs": [], @@ -85,105 +144,50 @@ }, { "cell_type": "code", - "execution_count": 11, + "execution_count": null, "id": "ee708c55-6981-4fa8-8623-7bf2938eae49", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "(1, 11552, 3)" - ] - }, - "execution_count": 11, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "coordinates.shape" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": null, "id": "04b29755-d938-4739-9435-c865a65ea76a", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "11552" - ] - }, - "execution_count": 14, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "item.num_atoms" ] }, { "cell_type": "code", - "execution_count": 19, + "execution_count": null, "id": "5ffd8058-86d0-4f42-9fb3-c5781a41da9d", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "11552" - ] - }, - "execution_count": 19, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "item.num_models*304" ] }, { "cell_type": "code", - "execution_count": 65, + "execution_count": null, "id": "227c1978-1155-4f8d-bf4e-2e2c2fd06bbb", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "760" - ] - }, - "execution_count": 65, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "len(item.sec_struct_list)" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": null, "id": "09122373-e2ed-4898-b60f-0bfd19b4ac57", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "11552" - ] - }, - "execution_count": 7, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "coordinates = np.column_stack([item.x_coord_list, item.y_coord_list, item.z_coord_list])\n", "coordinates = coordinates.reshape([-1, item.num_atoms, 3])\n", @@ -193,28 +197,17 @@ }, { "cell_type": "code", - "execution_count": 66, + "execution_count": null, "id": "8165caf4-39ef-4f07-87c8-92d32e71e93d", "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "760" - ] - }, - "execution_count": 66, - "metadata": {}, - "output_type": "execute_result" - } - ], + "outputs": [], "source": [ "38*20" ] }, { "cell_type": "code", - "execution_count": 67, + "execution_count": null, "id": "52146f9a-4d7c-409d-887a-1e3b3e082155", "metadata": {}, "outputs": [], @@ -224,7 +217,7 @@ }, { "cell_type": "code", - "execution_count": 69, + "execution_count": null, "id": "5f54c17c-ae9e-4585-ab69-6cef9e1e846d", "metadata": {}, "outputs": [], @@ -234,7 +227,7 @@ }, { "cell_type": "code", - "execution_count": 70, + "execution_count": null, "id": "4ca0d174-a2cd-4db3-9e10-b2105acf2c03", "metadata": {}, "outputs": [],