Skip to content

Commit

Permalink
Update jupyter notebook for checking cell object
Browse files Browse the repository at this point in the history
  • Loading branch information
choglass committed Nov 11, 2024
1 parent 7397a04 commit 2ec3135
Showing 1 changed file with 185 additions and 44 deletions.
229 changes: 185 additions & 44 deletions cell2mol/test/check_Cell_object.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"execution_count": null,
"metadata": {},
"outputs": [
{
Expand All @@ -11,7 +11,7 @@
"'2023.09.6'"
]
},
"execution_count": 1,
"execution_count": 71,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -31,71 +31,128 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 83,
"metadata": {},
"outputs": [],
"source": [
"refcell = np.load(\"ABIJEB/Ref_Cell_ABIJEB.cell\", allow_pickle=True)\n",
"unitcell = np.load(\"ABIJEB/Cell_ABIJEB.cell\", allow_pickle=True)"
"from cell2mol.elementdata import ElementData\n",
"from cell2mol.xyz2mol import get_atomic_valences\n",
"from collections import defaultdict\n",
"\n",
"elemdatabase = ElementData()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 91,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'Te'"
]
},
"execution_count": 91,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"elemdatabase.elementsym[52]"
]
},
{
"cell_type": "code",
"execution_count": 117,
"metadata": {},
"outputs": [],
"source": [
"ref = refcell.refmoleclist[0]"
"refcode = \"HUFDER\"\n",
"refcell = np.load(f\"{refcode}/Ref_Cell_{refcode}.cell\", allow_pickle=True)\n"
]
},
{
"cell_type": "code",
"execution_count": 24,
"execution_count": 118,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"N-O -1 [N-]=O\n",
"H20-C10-N2-S2 -2 [H]C([H])([S-])C([H])([H])N1C([H])([H])C([H])([H])C([H])([H])N(C([H])([H])C([H])([H])[S-])C([H])([H])C([H])([H])C1([H])[H]\n",
"Fe 2.0\n"
]
"data": {
"text/plain": [
"------------- Cell2mol CELL Object ----------------\n",
" Version = 2.0\n",
" Type = cell\n",
" Sub-Type = reference\n",
" Name (Refcode) = HUFDER\n",
" Num Atoms = 90\n",
" Cell Parameters a:c = [15.9997 13.4821 15.076 ]\n",
" Cell Parameters al:ga = [ 90. 102.669 90. ]\n",
"---------------------------------------------------\n",
" # of Ref Molecules: = 2\n",
" With Formulae: \n",
" 0: H26-C12-N4-Cl2-Fe \n",
" 1: H26-C12-N4-Cl2-Fe "
]
},
"execution_count": 118,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"met = ref.metals[0]\n",
"for lig in ref.ligands:\n",
" print(lig.formula, lig.totcharge, lig.smiles)\n",
"for met in ref.metals:\n",
" print(met.label, met.charge)"
"refcell"
]
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": null,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"H20-C10-N3-O-S2-Fe 0\n",
"Fe 3.0\n",
"H20-C10-N3-O-S2-Fe 0\n",
"Fe 3.0\n",
"H20-C10-N3-O-S2-Fe 0\n",
"Fe 3.0\n",
"H20-C10-N3-O-S2-Fe 0\n",
"Fe 3.0\n"
"Reference Molecule : H26-C12-N4-Cl2-Fe\n",
"\t Fe\n"
]
},
{
"ename": "AttributeError",
"evalue": "'ligand' object has no attribute 'smiles'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[120], line 6\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\t\u001b[39;00m\u001b[38;5;124m\"\u001b[39m, met\u001b[38;5;241m.\u001b[39mlabel)\n\u001b[1;32m 5\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m lig \u001b[38;5;129;01min\u001b[39;00m ref\u001b[38;5;241m.\u001b[39mligands:\n\u001b[0;32m----> 6\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\t\u001b[39;00m\u001b[38;5;124m\"\u001b[39m, lig\u001b[38;5;241m.\u001b[39mformula, \u001b[43mlig\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43msmiles\u001b[49m)\n\u001b[1;32m 8\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mUnique Species in Reference Cell:\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m 9\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m specie \u001b[38;5;129;01min\u001b[39;00m refcell\u001b[38;5;241m.\u001b[39munique_species:\n",
"\u001b[0;31mAttributeError\u001b[0m: 'ligand' object has no attribute 'smiles'"
]
}
],
"source": [
"for mol in unitcell.moleclist:\n",
" print(mol.formula, mol.totcharge)\n",
" for met in mol.metals:\n",
" print(met.label, met.charge)"
" for i, ref in enumerate(refcell.refmoleclist):\n",
" print(f\"Reference Molecule :\", ref.formula)\n",
" for met in ref.metals:\n",
" print(\"\\t\", met.label)\n",
" for lig in ref.ligands:\n",
" print(\"\\t\", lig.formula, lig.smiles)\n",
"\n",
"print(\"Unique Species in Reference Cell:\")\n",
"for specie in refcell.unique_species:\n",
" if specie.subtype == \"metal\":\n",
" print(\"\\t\", specie.formula)\n",
" else:\n",
" print(\"\\t\", specie.formula, specie.smiles) "
]
},
{
"cell_type": "code",
"execution_count": 68,
"metadata": {},
"outputs": [],
"source": [
"refcell = np.load(\"ABIJEB/Ref_Cell_ABIJEB.cell\", allow_pickle=True)\n",
"unitcell = np.load(\"ABIJEB/Cell_ABIJEB.cell\", allow_pickle=True)"
]
},
{
Expand All @@ -109,39 +166,123 @@
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [
{
"ename": "AttributeError",
"evalue": "'molecule' object has no attribute 'totcharge'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
"Cell \u001b[0;32mIn[73], line 2\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i, ref \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28menumerate\u001b[39m(refcell\u001b[38;5;241m.\u001b[39mrefmoleclist):\n\u001b[0;32m----> 2\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mReference Molecule \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mi\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m:\u001b[39m\u001b[38;5;124m\"\u001b[39m, ref\u001b[38;5;241m.\u001b[39mformula, \u001b[43mref\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mtotcharge\u001b[49m)\n\u001b[1;32m 3\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m met \u001b[38;5;129;01min\u001b[39;00m ref\u001b[38;5;241m.\u001b[39mmetals:\n\u001b[1;32m 4\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;130;01m\\t\u001b[39;00m\u001b[38;5;124m\"\u001b[39m, met\u001b[38;5;241m.\u001b[39mlabel, met\u001b[38;5;241m.\u001b[39mcharge)\n",
"\u001b[0;31mAttributeError\u001b[0m: 'molecule' object has no attribute 'totcharge'"
]
}
],
"source": [
"for i, ref in enumerate(refcell.refmoleclist):\n",
" print(f\"Reference Molecule :\", ref.formula, ref.totcharge)\n",
" for met in ref.metals:\n",
" print(\"\\t\", met.label, met.charge)\n",
" for lig in ref.ligands:\n",
" print(\"\\t\", lig.formula, lig.totcharge)\n",
"\n",
"print(\"Unique Species in Reference Cell:\")\n",
"for specie in refcell.unique_species:\n",
" if specie.subtype == \"metal\":\n",
" print(\"\\t\", specie.formula, specie.charge)\n",
" else:\n",
" print(\"\\t\", specie.formula, specie.totcharge) "
]
},
{
"cell_type": "code",
"execution_count": 70,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"N-O\n",
"-1\n",
"H20-C10-N2-S2\n",
"-2\n",
"Fe\n",
"3\n"
"Unitcell's Reference 0 H20-C10-N3-O-S2-Fe 0\n",
"\t Fe 3\n",
"\t N-O -1\n",
"\t H20-C10-N2-S2 -2\n",
"=============================================================\n",
"Unitcell's Molecule 0: H20-C10-N3-O-S2-Fe 0\n",
"\t Fe 3\n",
"\t N-O -1\n",
"\t\t N -1\n",
"\t\t O 0\n",
"\t H20-C10-N2-S2 -2\n",
"Unitcell's Molecule 1: H20-C10-N3-O-S2-Fe 0\n",
"\t Fe 3\n",
"\t N-O -1\n",
"\t\t N -1\n",
"\t\t O 0\n",
"\t H20-C10-N2-S2 -2\n",
"Unitcell's Molecule 2: H20-C10-N3-O-S2-Fe 0\n",
"\t Fe 3\n",
"\t N-O -1\n",
"\t\t N -1\n",
"\t\t O 0\n",
"\t H20-C10-N2-S2 -2\n",
"Unitcell's Molecule 3: H20-C10-N3-O-S2-Fe 0\n",
"\t Fe 3\n",
"\t N-O -1\n",
"\t\t N -1\n",
"\t\t O 0\n",
"\t H20-C10-N2-S2 -2\n",
"=============================================================\n",
"Unique Species in Unit Cell:\n",
"\t N-O -1\n",
"\t\t N -1\n",
"\t\t O 0\n",
"\t H20-C10-N2-S2 -2\n",
"\t Fe 3\n"
]
}
],
"source": [
"for i, ref in enumerate(unitcell.refmoleclist):\n",
" print(f\"Unitcell's Reference {i}\", ref.formula, ref.totcharge)\n",
" for met in ref.metals:\n",
" print(\"\\t\", met.label, met.charge)\n",
" for lig in ref.ligands:\n",
" print(\"\\t\", lig.formula, lig.totcharge)\n",
"print(\"=============================================================\")\n",
"for j, mol in enumerate(unitcell.moleclist):\n",
" print(f\"Unitcell's Molecule {j}:\", mol.formula, mol.totcharge)\n",
" for met in mol.metals:\n",
" print(\"\\t\",met.label, met.charge)\n",
" for lig in mol.ligands:\n",
" print(\"\\t\", lig.formula, lig.totcharge)\n",
" if lig.formula == \"N-O\":\n",
" for atom in lig.atoms:\n",
" print(\"\\t\\t\", atom.label, atom.charge)\n",
"print(\"=============================================================\")\n",
"print(\"Unique Species in Unit Cell:\")\n",
"for specie in unitcell.unique_species:\n",
" if specie.subtype == \"metal\":\n",
" print(specie.formula, specie.charge)\n",
" print(\"\\t\", specie.formula, specie.charge)\n",
" else:\n",
" print(specie.formula, specie.totcharge)"
" print(\"\\t\", specie.formula, specie.totcharge) \n",
" if specie.formula == \"N-O\":\n",
" for atom in specie.atoms:\n",
" print(\"\\t\\t\", atom.label, atom.charge)"
]
},
{
"cell_type": "code",
"execution_count": 23,
"execution_count": 34,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"H20-C10-N3-O-S2-Fe -1\n",
"Fe 2.0\n",
"H20-C10-N3-O-S2-Fe 0\n",
"Fe 3.0\n",
"N-O -1\n",
"H20-C10-N2-S2 -2\n"
]
Expand Down

0 comments on commit 2ec3135

Please sign in to comment.