From 5320af2846a7e199440ba216e3e9ac0839eefe64 Mon Sep 17 00:00:00 2001 From: Diego Prada Date: Sat, 18 May 2024 18:57:14 -0600 Subject: [PATCH] In process --- docs/contents/user/tools/basic/convert.ipynb | 183 +++++++++++++----- molsysmt/basic/get.py | 18 +- .../element/component/get_component_type.py | 48 ++--- .../element/molecule/get_molecule_name.py | 2 +- .../element/molecule/get_molecule_type.py | 2 - molsysmt/form/file_prmtop/__init__.py | 4 +- molsysmt/form/file_prmtop/attributes.py | 1 + .../form/file_prmtop/to_molsysmt_MolSys.py | 11 +- 8 files changed, 179 insertions(+), 90 deletions(-) diff --git a/docs/contents/user/tools/basic/convert.ipynb b/docs/contents/user/tools/basic/convert.ipynb index 99dae2646..7b611d4bf 100644 --- a/docs/contents/user/tools/basic/convert.ipynb +++ b/docs/contents/user/tools/basic/convert.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": { "tags": [ "remove-input" @@ -167,13 +167,13 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "application/vnd.jupyter.widget-view+json": { - "model_id": "360e85f74c0548f8855c20b444b52a12", + "model_id": "0a08fef286224b7b8baa6c276be670d9", "version_major": 2, "version_minor": 0 }, @@ -190,7 +190,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -200,63 +200,111 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": {}, "outputs": [ { - "name": "stdout", - "output_type": "stream", - "text": [ - "da1\n" - ] - }, - { - "ename": "NotCompatibleConversionError", - "evalue": "Error in conversion from file:prmtop to molsysmt.MolSys. The following input attributes of arguments are missing: {'solvent_dielectric', 'velocities', 'entity_type', 'cutoff_distance', 'entity_id', 'hydrogen_mass', 'salt_concentration', 'solute_dielectric', 'component_name', 'formal_charge', 'partial_charge', 'rigid_water', 'component_type', 'entity_name', 'kappa', 'component_id', 'flexible_constraints'}.", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mNotCompatibleConversionError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[3], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43mmsm\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43melement\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmolecule\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_molecule_type\u001b[49m\u001b[43m(\u001b[49m\u001b[43mprmtop_file\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43melement\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mmolecule\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mselection\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mall\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mredefine_indices\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", - "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/element/molecule/get_molecule_type.py:15\u001b[0m, in \u001b[0;36mget_molecule_type\u001b[0;34m(molecular_system, element, selection, redefine_indices, redefine_types, syntax, skip_digestion)\u001b[0m\n\u001b[1;32m 12\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m redefine_indices:\n\u001b[1;32m 14\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mda1\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[0;32m---> 15\u001b[0m molecule_types_from_molecule \u001b[38;5;241m=\u001b[39m \u001b[43mget_component_type\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmolecular_system\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43melement\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mcomponent\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;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\n\u001b[1;32m 16\u001b[0m \u001b[43m \u001b[49m\u001b[43mredefine_indices\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[43msyntax\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43msyntax\u001b[49m\u001b[43m)\u001b[49m\n\u001b[1;32m 17\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mda2\u001b[39m\u001b[38;5;124m'\u001b[39m)\n\u001b[1;32m 19\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m element \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m'\u001b[39m\u001b[38;5;124matom\u001b[39m\u001b[38;5;124m'\u001b[39m:\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/element/component/get_component_type.py:27\u001b[0m, in \u001b[0;36mget_component_type\u001b[0;34m(molecular_system, element, selection, redefine_indices, redefine_types, syntax, skip_digestion)\u001b[0m\n\u001b[1;32m 18\u001b[0m atom_indices \u001b[38;5;241m=\u001b[39m select(molecular_system, element\u001b[38;5;241m=\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124matom\u001b[39m\u001b[38;5;124m'\u001b[39m, selection\u001b[38;5;241m=\u001b[39mselection,\n\u001b[1;32m 19\u001b[0m syntax\u001b[38;5;241m=\u001b[39msyntax, skip_digestion\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[1;32m 21\u001b[0m \u001b[38;5;66;03m#if element!='atom':\u001b[39;00m\n\u001b[1;32m 22\u001b[0m \u001b[38;5;66;03m# aux_atom_indices = []\u001b[39;00m\n\u001b[1;32m 23\u001b[0m \u001b[38;5;66;03m# for aux in atom_indices:\u001b[39;00m\n\u001b[1;32m 24\u001b[0m \u001b[38;5;66;03m# aux_atom_indices += aux\u001b[39;00m\n\u001b[1;32m 25\u001b[0m \u001b[38;5;66;03m# atom_indices = aux_atom_indices\u001b[39;00m\n\u001b[0;32m---> 27\u001b[0m component_indices \u001b[38;5;241m=\u001b[39m \u001b[43mget_component_index\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmolecular_system\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43melement\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43matom\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[1;32m 28\u001b[0m \u001b[43m \u001b[49m\u001b[43mselection\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mall\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mredefine_indices\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 29\u001b[0m \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 31\u001b[0m unique_component_indices, first_atoms, n_atoms \u001b[38;5;241m=\u001b[39m np\u001b[38;5;241m.\u001b[39munique(component_indices, return_index\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m,\n\u001b[1;32m 32\u001b[0m return_counts\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n\u001b[1;32m 34\u001b[0m component_types\u001b[38;5;241m=\u001b[39m{}\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/element/component/get_component_index.py:18\u001b[0m, in \u001b[0;36mget_component_index\u001b[0;34m(molecular_system, element, selection, redefine_indices, syntax, skip_digestion)\u001b[0m\n\u001b[1;32m 14\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01mmolsysmt\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m convert, get\n\u001b[1;32m 16\u001b[0m component_index_of_atoms \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[0;32m---> 18\u001b[0m g \u001b[38;5;241m=\u001b[39m \u001b[43mconvert\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmolecular_system\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mto_form\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mnetworkx.Graph\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;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 20\u001b[0m components \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mlist\u001b[39m(nx\u001b[38;5;241m.\u001b[39mconnected_components(g))\n\u001b[1;32m 22\u001b[0m aux_n_components \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mlen\u001b[39m(components)\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/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:91\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 87\u001b[0m output \u001b[38;5;241m=\u001b[39m function(molecular_system, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mconversion_arguments, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\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[0;32m---> 91\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[38;5;124;43m'\u001b[39;49m\u001b[38;5;124;43mmolsysmt.MolSys\u001b[39;49m\u001b[38;5;124;43m'\u001b[39;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\n\u001b[1;32m 92\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[43msyntax\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43msyntax\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 93\u001b[0m output \u001b[38;5;241m=\u001b[39m _convert_one_to_one(output, \u001b[38;5;124m'\u001b[39m\u001b[38;5;124mmolsysmt.MolSys\u001b[39m\u001b[38;5;124m'\u001b[39m, to_form\u001b[38;5;241m=\u001b[39mto_form)\n\u001b[1;32m 95\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m output\n", - "File \u001b[0;32m~/repos@uibcdf/MolSysMT/molsysmt/basic/convert.py:85\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 82\u001b[0m missing_arguments\u001b[38;5;241m.\u001b[39mdiscard(\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mget_missing_bonds\u001b[39m\u001b[38;5;124m'\u001b[39m)\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[0;32m---> 85\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m NotCompatibleConversionError(from_form, to_form, missing_arguments)\n\u001b[1;32m 87\u001b[0m output \u001b[38;5;241m=\u001b[39m function(molecular_system, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mconversion_arguments, \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39mkwargs)\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[0;31mNotCompatibleConversionError\u001b[0m: Error in conversion from file:prmtop to molsysmt.MolSys. The following input attributes of arguments are missing: {'solvent_dielectric', 'velocities', 'entity_type', 'cutoff_distance', 'entity_id', 'hydrogen_mass', 'salt_concentration', 'solute_dielectric', 'component_name', 'formal_charge', 'partial_charge', 'rigid_water', 'component_type', 'entity_name', 'kappa', 'component_id', 'flexible_constraints'}." - ] + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
formn_atomsn_groupsn_componentsn_chainsn_moleculesn_entitiesn_watersn_peptidesn_structures
file:prmtop52071722171611716217151None
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 4, + "metadata": {}, + "output_type": "execute_result" } ], - "source": [ - "msm.element.molecule.get_molecule_type(prmtop_file, element='molecule', selection='all', redefine_indices=True)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], "source": [ "msm.info(prmtop_file)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
formn_atomsn_groupsn_componentsn_chainsn_moleculesn_entitiesn_structures
file:inpcrd5207NoneNoneNoneNoneNone1
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 5, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "msm.info(inpcrd_file)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -265,9 +313,54 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "\n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + " \n", + "
formn_atomsn_groupsn_componentsn_chainsn_moleculesn_entitiesn_watersn_peptidesn_structures
molsysmt.MolSys520717221716117162171511
\n" + ], + "text/plain": [ + "" + ] + }, + "execution_count": 7, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "msm.info(molecular_system)" ] diff --git a/molsysmt/basic/get.py b/molsysmt/basic/get.py index 62175e6a5..c2c5f0dde 100644 --- a/molsysmt/basic/get.py +++ b/molsysmt/basic/get.py @@ -257,16 +257,18 @@ def _piped_molecular_system(molecular_system, element, in_attributes): skip_digestion=True) if is_topological_attribute(in_attribute, skip_digestion=True): _, aux_form = where_is_attribute(molecular_system, in_attribute, skip_digestion=True) - if piped_topological_attribute[aux_form] not in aux_piped_topological_attribute: - aux_piped_topological_attribute.append(piped_topological_attribute[aux_form]) - if piped_any_attribute[aux_form] not in aux_piped_any_attribute: - aux_piped_any_attribute.append(piped_any_attribute[aux_form]) + if aux_form is not None: + if piped_topological_attribute[aux_form] not in aux_piped_topological_attribute: + aux_piped_topological_attribute.append(piped_topological_attribute[aux_form]) + if piped_any_attribute[aux_form] not in aux_piped_any_attribute: + aux_piped_any_attribute.append(piped_any_attribute[aux_form]) elif is_structural_attribute(in_attribute, skip_digestion=True): _, aux_form = where_is_attribute(molecular_system, in_attribute) - if piped_structural_attribute[aux_form] not in aux_piped_structural_attribute: - aux_piped_structural_attribute.append(piped_structural_attribute[aux_form]) - if piped_any_attribute[aux_form] not in aux_piped_any_attribute: - aux_piped_any_attribute.append(piped_any_attribute[aux_form]) + if aux_form is not None: + if piped_structural_attribute[aux_form] not in aux_piped_structural_attribute: + aux_piped_structural_attribute.append(piped_structural_attribute[aux_form]) + if piped_any_attribute[aux_form] not in aux_piped_any_attribute: + aux_piped_any_attribute.append(piped_any_attribute[aux_form]) n_top = len(aux_piped_topological_attribute) n_str = len(aux_piped_structural_attribute) diff --git a/molsysmt/element/component/get_component_type.py b/molsysmt/element/component/get_component_type.py index 2a701ee56..0d8d290b4 100644 --- a/molsysmt/element/component/get_component_type.py +++ b/molsysmt/element/component/get_component_type.py @@ -1,6 +1,7 @@ from molsysmt._private.digestion import digest +from molsysmt._private.variables import is_all import numpy as np - +import pandas as pd @digest() def get_component_type(molecular_system, element='atom', selection='all', redefine_indices=False, @@ -15,45 +16,43 @@ def get_component_type(molecular_system, element='atom', selection='all', redefi if redefine_indices: - atom_indices = select(molecular_system, element='atom', selection=selection, - syntax=syntax, skip_digestion=True) - - #if element!='atom': - # aux_atom_indices = [] - # for aux in atom_indices: - # aux_atom_indices += aux - # atom_indices = aux_atom_indices - component_indices = get_component_index(molecular_system, element='atom', selection='all', redefine_indices=True, skip_digestion=True) - unique_component_indices, first_atoms, n_atoms = np.unique(component_indices, return_index=True, - return_counts=True) + group_index_per_atom = get(molecular_system, element='atom', selection='all', group_index=True, + skip_digestion=True) - component_types={} + group_names, group_types = get(molecular_system, element='group', selection='all', group_name=True, + group_type=True, skip_digestion=True) - for component_index, first_atom, aux_n_atoms in zip(unique_component_indices, first_atoms, n_atoms): + group_names = np.array(group_names) + group_types = np.array(group_types) + + + aux_df = pd.DataFrame({'component_indices':component_indices, 'group_indices':group_index_per_atom}) + aux_dict = aux_df.groupby('component_indices')['group_indices'].unique().to_dict() + + component_types={} - atom_indices_component = list(np.arange(aux_n_atoms))+first_atom - aux_group_names, aux_group_types = get(molecular_system, element='group', - selection='atom_index in @atom_indices_component', - group_name=True, group_type=True, - syntax='MolSysMT', skip_digestion=True) + for component_index, group_indices in aux_dict.items(): - component_type = _get_component_type_from_group_names_and_types(aux_group_names, aux_group_types) + component_type = _get_component_type_from_group_names_and_types(group_names[group_indices], + group_types[group_indices]) component_types[component_index]=component_type if element == 'atom': + atom_indices = select(molecular_system, element='atom', selection=selection, + syntax=syntax, skip_digestion=True) output = [component_types[component_indices[ii]] for ii in atom_indices] elif element == 'group': output = [] group_indices = get(molecular_system, element='atom', - selection=atom_indices, group_indices=True, skip_digestion=True) + selection=selection, group_indices=True, skip_digestion=True) former_index = -1 for ii,jj,kk in zip(group_indices, atom_indices, component_indices): if ii!=former_index: @@ -63,13 +62,16 @@ def get_component_type(molecular_system, element='atom', selection='all', redefi elif element == 'component': - output = list(component_types.values()) + if is_all(selection): + output = list(component_types.values()) + else: + raise NotImplementedError else: raise NotImplementedError - del atom_indices, component_types, component_indices + del component_types, component_indices, group_index_per_atom, group_names, group_types else: diff --git a/molsysmt/element/molecule/get_molecule_name.py b/molsysmt/element/molecule/get_molecule_name.py index db13391ae..32ab68eba 100644 --- a/molsysmt/element/molecule/get_molecule_name.py +++ b/molsysmt/element/molecule/get_molecule_name.py @@ -4,7 +4,7 @@ @digest() def get_molecule_name(molecular_system, element='atom', selection='all', redefine_molecules=False, - redefine_names=False, syntax='MolSysMT'): + redefine_names=False, syntax='MolSysMT', skip_digestion=False): if redefine_molecules or redefine_names: diff --git a/molsysmt/element/molecule/get_molecule_type.py b/molsysmt/element/molecule/get_molecule_type.py index 33639544f..2c17773b0 100644 --- a/molsysmt/element/molecule/get_molecule_type.py +++ b/molsysmt/element/molecule/get_molecule_type.py @@ -11,10 +11,8 @@ def get_molecule_type(molecular_system, element='atom', selection='all', if redefine_indices: - print('da1') molecule_types_from_molecule = get_component_type(molecular_system, element='component', selection=selection, redefine_indices=True, syntax=syntax) - print('da2') if element == 'atom': aux = get(molecular_system, element='atom', selection=selection, syntax=syntax, diff --git a/molsysmt/form/file_prmtop/__init__.py b/molsysmt/form/file_prmtop/__init__.py index dcd780d67..33d1f371e 100644 --- a/molsysmt/form/file_prmtop/__init__.py +++ b/molsysmt/form/file_prmtop/__init__.py @@ -3,9 +3,11 @@ form_info = ["AMBER parameter/topology file format", "https://ambermd.org/FileFormats.php#topology"] -piped_topological_attribute = None +piped_topological_attribute = 'molsysmt.Topology' piped_structural_attribute = None piped_any_attribute = None +bonds_are_explicit = True +bonds_can_be_computed = False from .is_form import is_form diff --git a/molsysmt/form/file_prmtop/attributes.py b/molsysmt/form/file_prmtop/attributes.py index b94e1d29d..fcea9953c 100644 --- a/molsysmt/form/file_prmtop/attributes.py +++ b/molsysmt/form/file_prmtop/attributes.py @@ -41,6 +41,7 @@ attributes['n_lipids'] = True attributes['n_oligosaccharides'] = True attributes['n_saccharides'] = True +attributes['n_entities'] = True attributes['bond_index'] = True attributes['bond_id'] = True diff --git a/molsysmt/form/file_prmtop/to_molsysmt_MolSys.py b/molsysmt/form/file_prmtop/to_molsysmt_MolSys.py index 75976184b..7e171d5d0 100644 --- a/molsysmt/form/file_prmtop/to_molsysmt_MolSys.py +++ b/molsysmt/form/file_prmtop/to_molsysmt_MolSys.py @@ -1,22 +1,13 @@ from molsysmt._private.digestion import digest @digest(form='file:prmtop') -def to_molsysmt_MolSys(item, atom_indices='all', - component_id=None, component_type=None, component_name=None, - entity_id=None, entity_type=None, entity_name=None, - structure_id=None, coordinates=None, velocities=None, time=None, box=None, - formal_charge=None, partial_charge=None, forcefield=None, non_bonded_method=None, - cutoff_distance=None, switch_distance=None, dispersion_correction=None, ewald_error_tolerance=None, - hydrogen_mass=None, constraints=None, flexible_constraints=None, water_model=None, rigid_water=None, - implicit_solvent=None, solute_dielectric=None, solvent_dielectric=None, salt_concentration=None, - kappa=None): +def to_molsysmt_MolSys(item, atom_indices='all', skip_digestion=False): from molsysmt.native import MolSys, Structures from .to_molsysmt_Topology import to_molsysmt_Topology tmp_item = MolSys() tmp_item.topology = to_molsysmt_Topology(item, atom_indices=atom_indices) tmp_item.structures = Structures() - tmp_item.structures.append_structures(coordinates=coordinates) return tmp_item