Skip to content

Commit

Permalink
Small bugs fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
dprada committed Jul 3, 2024
1 parent 837a8e1 commit 5470a99
Show file tree
Hide file tree
Showing 12 changed files with 143 additions and 50 deletions.
2 changes: 1 addition & 1 deletion molsysmt/build/define_new_chain.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def define_new_chain(molecular_system, selection='all', chain_id=None, chain_nam
chain_name = 'A'

set(molecular_system, element='atom', selection='all', chain_index=0, skip_digestion=True)
set(molecular_system, element='chain', selection=0, chain_id=chain_id, chain_name=chain_name, skip_digestion=True)
set(molecular_system, element='chain', selection='all', chain_id=[chain_id], chain_name=[chain_name], skip_digestion=True)

else:

Expand Down
7 changes: 3 additions & 4 deletions molsysmt/data/_make/chicken_villin_HP35.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

files_to_be_purged = [
'pdb/1vii.pdb',
'mmtf/1vii.mmtf',
'h5msm/chicken_villin_HP35.h5msm',
'h5msm/chicken_villin_HP35_solvated.h5msm',
'dcd/traj_chicken_villin_HP35.dcd',
Expand All @@ -35,9 +34,9 @@
msm.convert('pdb_id:1vii', to_form='1vii.pdb')
msm.convert('pdb_id:1vii', to_form='1vii.bcif')
msm.convert('pdb_id:1vii', to_form='1vii.bcif.gz')
shutil.move('1vii.pdb', Path(data_dir, 'bcif/1vii.pdb'))
shutil.move('1vii.bcif', Path(data_dir, 'mmtf/1vii.bcif'))
shutil.move('1vii.bcif.gz', Path(data_dir, 'mmtf/1vii.bcif.gz'))
shutil.move('1vii.pdb', Path(data_dir, 'pdb/1vii.pdb'))
shutil.move('1vii.bcif', Path(data_dir, 'bcif/1vii.bcif'))
shutil.move('1vii.bcif.gz', Path(data_dir, 'bcif_gz/1vii.bcif.gz'))


# vacuum
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions molsysmt/form/molsysmt_Topology/set.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,13 @@ def set_chain_index_to_atom(item, indices='all', value=None, skip_digestion=Fals
if is_all(indices):
if len(value)==1:
item.atoms.chain_index=value[0]
n_chains = 1
else:
item.atoms.chain_index=value
n_chains = np.unique(value).shape[0]
if n_chains!=item.chains.shape[0]:
item.reset_chains(n_chains=n_chains)
item.rebuild_chains(redefine_ids=True, redefine_types=True, redefine_names=True)
else:
item.atoms.iloc[indices, 4]=value

Expand Down
19 changes: 2 additions & 17 deletions molsysmt/native/topology.py
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,7 @@ def rebuild_molecules(self, redefine_indices=True, redefine_ids=True, redefine_n
def rebuild_chains(self, redefine_ids=True, redefine_types=True, redefine_names=True):

from molsysmt.element.molecule import _singular_molecule_type_to_plural
from molsysmt.element.chain import all_chain_names

if redefine_ids:

Expand Down Expand Up @@ -720,23 +721,7 @@ def rebuild_chains(self, redefine_ids=True, redefine_types=True, redefine_names=

if redefine_names:

alphabet = string.ascii_uppercase
chain_name_list = []
ii = 0
while len(chain_name_list) < self.chains.shape[0]:
if ii < len(alphabet):
chain_name_list.append(alphabet[ii])
else:
for first_letter in alphabet:
for second_letter in alphabet:
chain_name_list.append(first_letter + second_letter)
if len(chain_name_list) >= self.chains.shape[0]:
break
if len(chain_name_list) >= self.chains.shape[0]:
break
ii += 1

self.chains["chain_name"]=np.array(chain_name_list[:self.chains.shape[0]], dtype=object)
self.chains["chain_name"]=np.array(all_chain_names[:self.chains.shape[0]], dtype=object)


def rebuild_entities(self, redefine_indices=True, redefine_ids=True, redefine_names=True, redefine_types=True):
Expand Down
138 changes: 121 additions & 17 deletions sandbox/Tests.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "bb0e9bda4b2a4a9eb6e171ee76c6ea86",
"model_id": "ea2e8c1e89bc4d219d42d82c9108c88f",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -35,54 +35,158 @@
},
{
"cell_type": "code",
"execution_count": null,
"id": "a673846b-5259-4acc-a751-9a9df5ba7a46",
"execution_count": 2,
"id": "e4442462-d13a-4102-831e-53432b0b04de",
"metadata": {},
"outputs": [],
"source": [
"molecular_system = msm.build.build_peptide('AlaValPro', to_form='molsysmt.MolSys')"
"molsys_1 = msm.convert(systems['alanine dipeptide']['alanine_dipeptide.h5msm'], to_form='molsysmt.MolSys')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "3cde5516-66de-4705-8539-ea9814f7ab2c",
"execution_count": 3,
"id": "48649be7-9724-48f0-9f73-1c8ad9f577d2",
"metadata": {},
"outputs": [],
"source": [
"temp_molecular_system = msm.convert(molecular_system, to_form='pdbfixer.PDBFixer')"
"molsys_2 = msm.structure.translate(molsys_1, translation='[0.5, 0.0, 0.0] nm')"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "1b6627fa-c6cc-4262-a51c-ec50ed919840",
"execution_count": 4,
"id": "588d98cf-50f6-4a99-a562-d207ffb7e869",
"metadata": {},
"outputs": [],
"source": [
"msm.select(temp_molecular_system, selection='component_type in [\"peptide\", \"protein\"]')"
"molsys_merged = msm.merge([molsys_1, molsys_2], keep_ids=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b13310ce-2b0b-429c-a6e7-b0a53074d34c",
"execution_count": 5,
"id": "038cd459-facb-47d5-ae4f-26deefc4a9e1",
"metadata": {},
"outputs": [],
"source": [
"msm.build.define_new_chain(molsys_merged)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "8aa9e648-9c87-4701-bba5-3bf2d5aff9d9",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<div>\n",
"<style scoped>\n",
" .dataframe tbody tr th:only-of-type {\n",
" vertical-align: middle;\n",
" }\n",
"\n",
" .dataframe tbody tr th {\n",
" vertical-align: top;\n",
" }\n",
"\n",
" .dataframe thead th {\n",
" text-align: right;\n",
" }\n",
"</style>\n",
"<table border=\"1\" class=\"dataframe\">\n",
" <thead>\n",
" <tr style=\"text-align: right;\">\n",
" <th></th>\n",
" <th>chain_id</th>\n",
" <th>chain_name</th>\n",
" <th>chain_type</th>\n",
" </tr>\n",
" </thead>\n",
" <tbody>\n",
" <tr>\n",
" <th>0</th>\n",
" <td>0</td>\n",
" <td>A</td>\n",
" <td>system</td>\n",
" </tr>\n",
" </tbody>\n",
"</table>\n",
"</div>"
],
"text/plain": [
" chain_id chain_name chain_type\n",
"0 0 A system"
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"molsys_merged.topology.chains"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "0d985652-a9f6-4617-b92e-c7fef89f24f6",
"metadata": {},
"outputs": [],
"source": [
"msm.get(temp_molecular_system, element='component', selection='component_type in [\"peptide\", \"protein\"]',\n",
" atom_index=True)"
"view = msm.view(molsys_merged, viewer='NGLView')"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "4eff5af0-50ea-4c4a-a6b9-73c21170159e",
"metadata": {},
"outputs": [],
"source": [
"comparison = msm.compare(view, molsys_merged, attribute_type='topological',\n",
" coordinates=True)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "ddbf7195-e17f-43b4-a70a-8074f72d7ee5",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"comparison"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a15ccef9-8872-4d86-83be-10c624e7a4d1",
"id": "9c305a1e-1f6c-4ecf-8138-0f55ade00df8",
"metadata": {},
"outputs": [],
"source": [
"msm.get(molecular_system, element='component', selection='component_type in [\"peptide\", \"protein\"]',\n",
" atom_index=True)"
" molsys_1 = msm.convert(systems['alanine dipeptide']['alanine_dipeptide.h5msm'], to_form='molsysmt.MolSys')\n",
" molsys_2 = msm.structure.translate(molsys_1, translation='[0.5, 0.0, 0.0] nm')\n",
" molsys_merged = msm.merge([molsys_1, molsys_2], keep_ids=False)\n",
" msm.build.define_new_chain(molsys_merged, selection='all', chain_id=0, chain_name='A')\n",
" view = msm.view(molsys_merged, viewer='NGLView')\n",
" comparison = msm.compare(view, molsys_merged, attribute_type='topological',\n",
" coordinates=True)\n",
" assert comparison\n"
]
}
],
Expand Down
6 changes: 0 additions & 6 deletions tests/basic/convert/one_to_one/test_convert_from_file_mmtf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ def test_file_mmtf_to_molsysmt_MolSys_1():
form = msm.get_form(molsys)
assert 'molsysmt.MolSys'==form

def test_file_mmtf_to_molsysmt_MolSys_2():
molsys = systems['chicken villin HP35']['1vii.mmtf']
molsys = msm.convert(molsys, to_form='molsysmt.MolSys')
form = msm.get_form(molsys)
assert 'molsysmt.MolSys'==form

#def test_file_mmtf_to_string_aminoacids1():
# molsys = tests_systems['T4 lysozyme L99A']['181l.mmtf']
# molsys = msm.convert(molsys, to_form='string:aminoacids1')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,17 @@ def test_string_pdb_id_to_file_pdb():
os.remove(molsys)
assert 'file:pdb'==form

def test_string_pdb_id_to_file_mmtf():
molsys = msm.convert('pdb_id:181l', to_form='181l.mmtf')
def test_string_pdb_id_to_file_bcif():
molsys = msm.convert('pdb_id:181l', to_form='181l.bcif')
form = msm.get_form(molsys)
os.remove(molsys)
assert 'file:mmtf'==form
assert 'file:bcif'==form

def test_string_pdb_id_to_file_bcif_gz():
molsys = msm.convert('pdb_id:181l', to_form='181l.bcif.gz')
form = msm.get_form(molsys)
os.remove(molsys)
assert 'file:bcif.gz'==form

def test_string_pdb_id_to_mdtraj_Trajectory():
molsys = msm.convert('pdb_id:181l', to_form='mdtraj.Trajectory')
Expand Down
2 changes: 1 addition & 1 deletion tests/basic/test_is_composed_of.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ def test_is_composed_of_5():
assert output == False

def test_is_composed_of_6():
output = msm.is_composed_of(molsys, ions=2, waters=1483, peptides=1)
output = msm.is_composed_of(molsys, ions=2, waters=1283, peptides=1)
assert output == True

2 changes: 1 addition & 1 deletion tests/basic/view/test_view_molsysmt_MolSys_with_NGLView.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def test_view_molsyst_MolSys_with_NGLView_3():
molsys_1 = msm.convert(systems['alanine dipeptide']['alanine_dipeptide.h5msm'], to_form='molsysmt.MolSys')
molsys_2 = msm.structure.translate(molsys_1, translation='[0.5, 0.0, 0.0] nm')
molsys_merged = msm.merge([molsys_1, molsys_2], keep_ids=False)
msm.build.define_new_chain(molsys_merged)
msm.build.define_new_chain(molsys_merged, selection='all', chain_id=0, chain_name='A')
view = msm.view(molsys_merged, viewer='NGLView')
comparison = msm.compare(view, molsys_merged, attribute_type='topological',
coordinates=True)
Expand Down

0 comments on commit 5470a99

Please sign in to comment.