<jupyter_start><jupyter_text>Introduction This notebook demonstrates pymatgen's functionality in terms of creating and editing molecules, as well as its integration with OpenBabel. For the latter, please note that you will need to have openbabel with python bindings installed. Please refer to pymatgen's documentation for installation details.Written using:- pymatgen==2018.3.13  Molecules<jupyter_code>from pymatgen.core import Molecule
# Create a methane molecule.
coords = [[0.000000, 0.000000, 0.000000],
          [0.000000, 0.000000, 1.089000],
          [1.026719, 0.000000, -0.363000],
          [-0.513360, -0.889165, -0.363000],
          [-0.513360, 0.889165, -0.363000]]
mol = Molecule(["C", "H", "H", "H", "H"], coords)
print(mol)
# A Molecule is simply a list of Sites.
print(mol[0])
print(mol[1])
# Break a Molecule into two by breaking a bond.
for frag in mol.break_bond(0, 1):
    print(frag)
# Getting neighbors that are within 3 angstroms from C atom.
print(mol.get_neighbors(mol[0], 3))
#Detecting bonds
print(mol.get_covalent_bonds())
# If you need to run the molecule in a box with a periodic boundary condition
# code, you can generate the boxed structure as follows (in a 10Ax10Ax10A box)
structure = mol.get_boxed_structure(10, 10, 10)
print(structure)
# Writing to XYZ files (easy to open with many molecule file viewers)
from pymatgen.io.xyz import XYZ
xyz = XYZ(mol)
xyz.write_file("methane.xyz")<jupyter_output><empty_output><jupyter_text>Openbabel interface This section demonstrates pymatgen's integration with openbabel.<jupyter_code>from pymatgen.io.babel import BabelMolAdaptor
import pybel as pb
a = BabelMolAdaptor(mol)
# Create a pybel.Molecule, which simplifies a lot of access
pm = pb.Molecule(a.openbabel_mol)
# Print canonical SMILES representation (unique and comparable).
print("Canonical SMILES = {}".format(pm.write("can")))
# Print Inchi representation
print("Inchi= {}".format(pm.write("inchi")))
# pb.outformats provides a listing of available formats. 
# Let's do a write to the commonly used PDB file.
pm.write("pdb", filename="methane.pdb", overwrite=True)
# Generating ethylene carbonate (SMILES obtained from Wikipedia)
# And displaying the svg.
ec = pb.readstring("smi", "C1COC(=O)O1")
ec.make3D()
from IPython.core.display import SVG, display_svg
svg = SVG(ec.write("svg"))
display_svg(svg)<jupyter_output><empty_output><jupyter_text>Input/Output Pymatgen has built-in support for the XYZ and Gaussian, NWchem file formats. It also has support for most other file formats if you have openbabel with Python bindings installed.<jupyter_code>print(mol.to(fmt="xyz"))
print(mol.to(fmt="g09"))
print(mol.to(fmt="pdb")) #Needs Openbabel.

mol.to(filename="methane.xyz")
mol.to(filename="methane.pdb") #Needs Openbabel.

print(Molecule.from_file("methane.pdb"))<jupyter_output><empty_output><jupyter_text>For more fine-grained control over output, you can use the underlying IO classes Gaussian and Nwchem, two commonly used computational chemistry programs.<jupyter_code>from pymatgen.io.gaussian import GaussianInput
gau = GaussianInput(mol, charge=0, spin_multiplicity=1, title="methane", 
                    functional="B3LYP", basis_set="6-31G(d)", 
                    route_parameters={'Opt': "", "SCF": "Tight"},
                    link0_parameters={"%mem": "1000MW"})
print(gau)
# A standard relaxation + SCF energy nwchem calculation input file for methane.
from pymatgen.io.nwchem import NwTask, NwInput
tasks = [
    NwTask.dft_task(mol, operation="optimize", xc="b3lyp",
                    basis_set="6-31G"),
    NwTask.dft_task(mol, operation="freq", xc="b3lyp",
                    basis_set="6-31G"),
    NwTask.dft_task(mol, operation="energy", xc="b3lyp",
                    basis_set="6-311G"),
]
nwi = NwInput(mol, tasks, geometry_options=["units", "angstroms"])
print(nwi)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12071189063709054, 'fraction_numerical': 0.04126902244003095, 'mean_word_length': 4.7880597014925375, 'pattern_counts': {'":': 2, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '467478', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1458, 'n_tokens_neox': 1273, 'n_words': 366, 'path': 'notebooks/2013-01-01-Molecule.ipynb', 'repo_name': 'zenandrea/matgenb', 'size': '3877'}