Skip to content

Commit

Permalink
Merge pull request #99 from dprada/main
Browse files Browse the repository at this point in the history
Bugs fixed
  • Loading branch information
dprada authored Feb 14, 2023
2 parents 186a375 + c9531ba commit 11feb83
Show file tree
Hide file tree
Showing 22 changed files with 490 additions and 145 deletions.
2 changes: 1 addition & 1 deletion dev_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
## Get

- n_atoms is always an integer even when there is no topological info.
- n_structures is None when the form has no structural info. If the form can store structures n_structures is always an integer.
- n_structures is None when the form has no structural info. If the form can store structures n_structures is always an integer (0, if there are no structures in the form).
- if time, box, etc... (structural attributes) are not present in an object... the output is a list with as many Nones as structure_indices.

## Iterator
Expand Down
94 changes: 88 additions & 6 deletions docs/contents/user/tools/basic/has_attribute.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
"cell_type": "code",
"execution_count": 2,
"id": "ccf509b5-a79a-41f7-b432-789945069627",
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"application/vnd.jupyter.widget-view+json": {
"model_id": "e8d6a25621fa4408bbe762fa10d9d03a",
"model_id": "d8b69a8d627f44ea9a5003b579baf6df",
"version_major": 2,
"version_minor": 0
},
Expand All @@ -58,7 +60,9 @@
"cell_type": "code",
"execution_count": 3,
"id": "06c8778b-b835-4bf3-9a10-448add565480",
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"molecular_system = msm.demo['pentalanine']['pentalanine.inpcrd']"
Expand All @@ -68,7 +72,9 @@
"cell_type": "code",
"execution_count": 4,
"id": "86924b7a-ae89-49b9-8ef1-698fa31b9499",
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
Expand All @@ -89,7 +95,9 @@
"cell_type": "code",
"execution_count": 5,
"id": "032488bc-9cc2-4f15-906b-717849d17885",
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
Expand All @@ -106,6 +114,72 @@
"msm.has_attribute(molecular_system, attribute='group_name')"
]
},
{
"cell_type": "markdown",
"id": "310b3dc5-752b-4a47-9803-cf71972e0599",
"metadata": {},
"source": [
"Two special strings are accepted by this method in addition to any attribute name: \"topological\" and \"structural\". These words allow us to know if a form has any topological or structural attribute. Let's illustrate this case with some few examples:"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "700c4658-5cac-4199-8a52-5d89128e4a73",
"metadata": {
"tags": []
},
"outputs": [],
"source": [
"psf_file = msm.demo['membrane']['membrane.psf']"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "db4025f9-bac9-44f8-a470-b0eb1ab12f09",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"msm.has_attribute(psf_file, 'topological')"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "41c35ded-2e7c-469f-b039-7d61bd46fe1f",
"metadata": {
"tags": []
},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"msm.has_attribute(psf_file, 'structural')"
]
},
{
"cell_type": "markdown",
"id": "72d30572-e39a-40dc-9544-a69157b0fe5b",
Expand All @@ -127,6 +201,14 @@
"{func}`molsysmt.basic.has_attribute`\n",
"```"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6a42b74a-129d-4f52-92e8-0e0f11428ded",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
Expand All @@ -145,7 +227,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.13"
"version": "3.9.16"
}
},
"nbformat": 4,
Expand Down
7 changes: 5 additions & 2 deletions molsysmt/_private/digestion/argument/attribute.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ def digest_attribute(attribute, caller=None):

from molsysmt.attribute import is_attribute

if is_attribute(attribute):
return attribute
if is_attribute(attribute.lower()):
return attribute.lower()
elif caller == 'molsysmt.basic.has_attribute.has_attribute':
if attribute.lower() in ['structural', 'topological']:
return attribute.lower()

raise ArgumentError('attribute', value=attribute, caller=caller, message=None)

5 changes: 5 additions & 0 deletions molsysmt/api_forms/api_file_dcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,9 @@ def to_molsysmt_Structures(item, molecular_system, atom_indices='all', structure

return file_dcd_to_molsysmt_Structures(item, atom_indices=atom_indices, structure_indices=structure_indices)

def to_molsysmt_MolSys(item, molecular_system, atom_indices='all', structure_indices='all'):
from molsysmt.form.file_dcd import to_molsysmt_MolSys as file_dcd_to_molsysmt_MolSys

return file_dcd_to_molsysmt_MolSys(item, atom_indices=atom_indices, structure_indices=structure_indices)


20 changes: 13 additions & 7 deletions molsysmt/api_forms/api_file_psf.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,23 @@
def to_molsysmt_MolSys(item, molecular_system, atom_indices='all', structure_indices='all'):

from molsysmt.form.file_psf import to_molsysmt_MolSys as file_psf_to_molsysmt_MolSys
from molsysmt import convert
from molsysmt import convert, has_attribute

molsysmt_structures = convert(molecular_system, selection=atom_indices, structure_indices=structure_indices,
if has_attribute(molecular_system, 'structural'):

molsysmt_structures = convert(molecular_system, selection=atom_indices, structure_indices=structure_indices,
to_form='molsysmt.Structures')

coordinates = molsysmt_structures.coordinates
time = molsysmt_structures.time
box = molsysmt_structures.box
structure_id = molsysmt_structures.structure_id
tmp_item = file_psf_to_molsysmt_MolSys(item, atom_indices=atom_indices, coordinates=coordinates,
coordinates = molsysmt_structures.coordinates
time = molsysmt_structures.time
box = molsysmt_structures.box
structure_id = molsysmt_structures.structure_id

tmp_item = file_psf_to_molsysmt_MolSys(item, atom_indices=atom_indices, coordinates=coordinates,
time=time, box=box, structure_id=structure_id)
else:

tmp_item = file_psf_to_molsysmt_MolSys(item, atom_indices=atom_indices)

return tmp_item

Expand Down
1 change: 1 addition & 0 deletions molsysmt/attribute/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from .is_attribute import is_attribute
from .is_structural_attribute import is_structural_attribute
from .is_topological_attribute import is_topological_attribute

Loading

0 comments on commit 11feb83

Please sign in to comment.