Skip to content

Commit

Permalink
Fixes for openbabel parsing and output.
Browse files Browse the repository at this point in the history
Revamped examples for basic functionality in Structures and Molecules.


Former-commit-id: e6cf14a18884d6ada8ab972bd4fddf6f858d5510 [formerly a95ff35]
Former-commit-id: 9d08d83b76fc56a24f83e62eec2ab4adb6fd09d2
  • Loading branch information
shyuep committed Sep 12, 2014
1 parent 0c6be72 commit 2e530b4
Show file tree
Hide file tree
Showing 5 changed files with 211 additions and 53 deletions.
119 changes: 96 additions & 23 deletions examples/Basic functionality.ipynb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"metadata": {
"name": ""
"name": "",
"signature": "sha256:22c38efd64283402a562a1901d5f0c4f35a9d052e62861db275c1a0fb73e0f68"
},
"nbformat": 3,
"nbformat_minor": 0,
Expand Down Expand Up @@ -55,9 +56,9 @@
"collapsed": false,
"input": [
"si = mg.Element(\"Si\")\n",
"print \"Atomic mass of Si is {}\".format(si.atomic_mass)\n",
"print \"Si has a melting point of {}\".format(si.melting_point)\n",
"print \"Ionic radii for Si: {}\".format(si.ionic_radii)"
"print(\"Atomic mass of Si is {}\".format(si.atomic_mass))\n",
"print(\"Si has a melting point of {}\".format(si.melting_point))\n",
"print(\"Ionic radii for Si: {}\".format(si.ionic_radii))"
],
"language": "python",
"metadata": {},
Expand Down Expand Up @@ -85,7 +86,7 @@
"cell_type": "code",
"collapsed": false,
"input": [
"print \"Atomic mass of Si in kg: {}\".format(si.atomic_mass.to(\"kg\"))"
"print(\"Atomic mass of Si in kg: {}\".format(si.atomic_mass.to(\"kg\")))"
],
"language": "python",
"metadata": {},
Expand All @@ -112,8 +113,8 @@
"collapsed": false,
"input": [
"fe2 = mg.Specie(\"Fe\", 2)\n",
"print fe2.atomic_mass\n",
"print fe2.ionic_radius"
"print(fe2.atomic_mass)\n",
"print(fe2.ionic_radius)"
],
"language": "python",
"metadata": {},
Expand Down Expand Up @@ -141,10 +142,10 @@
"collapsed": false,
"input": [
"comp = mg.Composition(\"Fe2O3\")\n",
"print \"Weight of Fe2O3 is {}\".format(comp.weight)\n",
"print \"Amount of Fe in Fe2O3 is {}\".format(comp[\"Fe\"])\n",
"print \"Atomic fraction of Fe is {}\".format(comp.get_atomic_fraction(\"Fe\"))\n",
"print \"Weight fraction of Fe is {}\".format(comp.get_wt_fraction(\"Fe\"))"
"print(\"Weight of Fe2O3 is {}\".format(comp.weight))\n",
"print(\"Amount of Fe in Fe2O3 is {}\".format(comp[\"Fe\"]))\n",
"print(\"Atomic fraction of Fe is {}\".format(comp.get_atomic_fraction(\"Fe\")))\n",
"print(\"Weight fraction of Fe is {}\".format(comp.get_wt_fraction(\"Fe\")))"
],
"language": "python",
"metadata": {},
Expand Down Expand Up @@ -183,7 +184,7 @@
"input": [
"# Creates cubic Lattice with lattice parameter 4.2\n",
"lattice = mg.Lattice.cubic(4.2)\n",
"print lattice.lengths_and_angles"
"print(lattice.lengths_and_angles)"
],
"language": "python",
"metadata": {},
Expand All @@ -210,8 +211,8 @@
"collapsed": false,
"input": [
"structure = mg.Structure(lattice, [\"Cs\", \"Cl\"], [[0, 0, 0], [0.5, 0.5, 0.5]])\n",
"print \"Unit cell vol = {}\".format(structure.volume)\n",
"print \"First site of the structure is {}\".format(structure[0])"
"print(\"Unit cell vol = {}\".format(structure.volume))\n",
"print(\"First site of the structure is {}\".format(structure[0]))"
],
"language": "python",
"metadata": {},
Expand Down Expand Up @@ -244,7 +245,7 @@
"structure[-1] = \"Li\" #Change the last added atom to Li.\n",
"structure[0] = \"Cs\", [0.01, 0.5, 0] #Shift the first atom by 0.01 in fractional coordinates in the x-direction.\n",
"immutable_structure = mg.IStructure.from_sites(structure) #Create an immutable structure (cannot be modified).\n",
"print immutable_structure"
"print(immutable_structure)"
],
"language": "python",
"metadata": {},
Expand Down Expand Up @@ -293,7 +294,7 @@
"#Determining the symmetry\n",
"from pymatgen.symmetry.finder import SymmetryFinder\n",
"finder = SymmetryFinder(structure)\n",
"print \"The spacegroup is {}\".format(finder.get_spacegroup_symbol())"
"print(\"The spacegroup is {}\".format(finder.get_spacegroup_symbol()))"
],
"language": "python",
"metadata": {},
Expand Down Expand Up @@ -324,7 +325,7 @@
"s1 = mg.Structure(lattice, [\"Cs\", \"Cl\"], [[0, 0, 0], [0.5, 0.5, 0.5]])\n",
"s2 = mg.Structure(mg.Lattice.cubic(5), [\"Rb\", \"F\"], [[0, 0, 0], [0.5, 0.5, 0.5]])\n",
"m = StructureMatcher()\n",
"print m.fit_anonymous(s1, s2) #Returns a mapping which maps s1 and s2 onto each other. Strict element fitting is also available."
"print(m.fit_anonymous(s1, s2)) #Returns a mapping which maps s1 and s2 onto each other. Strict element fitting is also available."
],
"language": "python",
"metadata": {},
Expand All @@ -333,7 +334,7 @@
"output_type": "stream",
"stream": "stdout",
"text": [
"{Comp: Cl1: Comp: F1, Comp: Cs1: Comp: Rb1}\n"
"True\n"
]
}
],
Expand All @@ -359,16 +360,88 @@
"collapsed": false,
"input": [
"#Convenient IO to various formats. Format is intelligently determined from file name and extension.\n",
"mg.write_structure(structure, \"POSCAR\")\n",
"mg.write_structure(structure, \"CsCl.cif\")\n",
"structure.to(filename=\"POSCAR\")\n",
"structure.to(filename=\"CsCl.cif\")\n",
"\n",
"#Or if you just supply fmt, you simply get a string.\n",
"print(structure.to(fmt=\"poscar\"))\n",
"print(structure.to(fmt=\"cif\"))"
],
"language": "python",
"metadata": {},
"outputs": [
{
"output_type": "stream",
"stream": "stdout",
"text": [
"Cs3 Li1 Cl4\n",
"1.0\n",
"8.400000 0.000000 0.000000\n",
"0.000000 8.400000 0.000000\n",
"0.000000 0.000000 4.200000\n",
"Cs Cl Li\n",
"3 4 1\n",
"direct\n",
"0.010000 0.500000 0.000000 Cs\n",
"0.500000 0.000000 0.000000 Cs\n",
"0.500000 0.500000 0.000000 Cs\n",
"0.250000 0.250000 0.500000 Cl\n",
"0.250000 0.750000 0.500000 Cl\n",
"0.750000 0.250000 0.500000 Cl\n",
"0.750000 0.750000 0.500000 Cl\n",
"0.000000 0.000000 0.000000 Li\n",
"\n",
"#generated using pymatgen\n",
"data_Cs3LiCl4\n",
"_symmetry_space_group_name_H-M 'P 1'\n",
"_cell_length_a 8.40000000\n",
"_cell_length_b 8.40000000\n",
"_cell_length_c 4.20000000\n",
"_cell_angle_alpha 90.00000000\n",
"_cell_angle_beta 90.00000000\n",
"_cell_angle_gamma 90.00000000\n",
"_symmetry_Int_Tables_number 1\n",
"_chemical_formula_structural Cs3LiCl4\n",
"_chemical_formula_sum 'Cs3 Li1 Cl4'\n",
"_cell_volume 296.352\n",
"_cell_formula_units_Z 1\n",
"loop_\n",
" _symmetry_equiv_pos_site_id\n",
" _symmetry_equiv_pos_as_xyz\n",
" 1 'x, y, z'\n",
"loop_\n",
" _atom_site_type_symbol\n",
" _atom_site_label\n",
" _atom_site_symmetry_multiplicity\n",
" _atom_site_fract_x\n",
" _atom_site_fract_y\n",
" _atom_site_fract_z\n",
" _atom_site_occupancy\n",
" Cs Cs1 1 0.010000 0.500000 0.000000 1\n",
" Cs Cs2 1 0.500000 0.000000 0.000000 1\n",
" Cs Cs3 1 0.500000 0.500000 0.000000 1\n",
" Cl Cl4 1 0.250000 0.250000 0.500000 1\n",
" Cl Cl5 1 0.250000 0.750000 0.500000 1\n",
" Cl Cl6 1 0.750000 0.250000 0.500000 1\n",
" Cl Cl7 1 0.750000 0.750000 0.500000 1\n",
" Li Li8 1 0.000000 0.000000 0.000000 1\n",
"\n"
]
}
],
"prompt_number": 11
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"#Reading a structure from a file.\n",
"structure = mg.read_structure(\"POSCAR\")"
"structure = mg.Structure.from_file(\"POSCAR\")"
],
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 11
"prompt_number": 12
},
{
"cell_type": "markdown",
Expand All @@ -388,7 +461,7 @@
"language": "python",
"metadata": {},
"outputs": [],
"prompt_number": 12
"prompt_number": 13
},
{
"cell_type": "heading",
Expand Down
Loading

0 comments on commit 2e530b4

Please sign in to comment.