{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# Import all the libraries\nimport numpy as np\nimport pandas as pd\nimport matplotlib.pyplot as plt\nimport seaborn as sns\nfrom ase import Atoms\nimport ase.visualize\nfrom mpl_toolkits.mplot3d import Axes3D\n\nsns.set()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import os\ninput_folder = '/kaggle/input'\nos.listdir(input_folder)","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"# Obtain all the information possible from the csv files.\ninput_folder = '/kaggle/input'\n\npotential_energy = pd.read_csv(f'{input_folder}/potential_energy.csv')\ndipole_moments = pd.read_csv(f'{input_folder}/dipole_moments.csv')\nmulliken_charges = pd.read_csv(f'{input_folder}/mulliken_charges.csv')\nmagnetic_shielding_tensors = pd.read_csv(f'{input_folder}/magnetic_shielding_tensors.csv')\nscalar_coupling_contributions = pd.read_csv(f'{input_folder}/scalar_coupling_contributions.csv')\nstructure = pd.read_csv(f'{input_folder}/structures.csv')\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"characteristics = [potential_energy, dipole_moments, mulliken_charges, magnetic_shielding_tensors, scalar_coupling_contributions, structure]\nfor element in characteristics:\n    print(element.info())\n    print('')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Check out how are the data distributed in each dataframe, see the dimensions to know which to concatenate\n\nfor element in characteristics:\n    print(element.head())\n    print(element.shape[0])\n    print('')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Concatenate potential energy and dipole moments\n\nenergy_dipole = pd.concat([potential_energy, dipole_moments],axis=1)\nenergy_dipole = energy_dipole.loc[:,~energy_dipole.columns.duplicated()]\nenergy_dipole.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Concatenate mulliken charges and the magnetic shielding tensors\n\nmulliken_magnetic = pd.concat([mulliken_charges, magnetic_shielding_tensors],axis=1)\nmulliken_magnetic = mulliken_magnetic.loc[:,~mulliken_magnetic.columns.duplicated()]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Reduce the size of the structure file in order to have the information for all particles\n\nother_items = set(mulliken_magnetic['molecule_name'].value_counts().index)\nall_items = set(structure['molecule_name'].value_counts().index)\ncompliment = all_items.intersection(other_items)\nreduced_structure = structure[structure.molecule_name.isin(compliment)]","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Add more variables to the mulliken_magnetic_structure\n\nmulliken_magnetic_structure = mulliken_magnetic\nmulliken_magnetic_structure['atom'] = list(reduced_structure['atom'])\nmulliken_magnetic_structure['x'] = list(reduced_structure['x'])\nmulliken_magnetic_structure['y'] = list(reduced_structure['y'])\nmulliken_magnetic_structure['z'] = list(reduced_structure['z'])\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Add the number of atoms pero particle\nenergy_dipole['number_of_atoms'] = list(mulliken_magnetic_structure.molecule_name.value_counts().sort_index())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"\n# print dataframes:\nmulliken_magnetic_structure.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"energy_dipole.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"energy_dipole.describe().T","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"# Show the distributions for each energy and dipole moment\n\nplt.hist(energy_dipole.potential_energy, bins = 100, color='red')\nplt.title('Potential Energy Distribution')\nplt.xlabel('Potential Energy')\nplt.ylabel('Count')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.pairplot(energy_dipole[['X','Y','Z']], diag_kind=\"kde\")\nplt.suptitle('Dipole moment Components \\n')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.violinplot(energy_dipole.number_of_atoms, showmeans=True, color='Green')\nplt.title('Distribution and dispersion of the number of atoms')\nplt.xlabel('Number of atoms')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"mms = mulliken_magnetic_structure\nmolecule = energy_dipole['molecule_name']","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"\n# Matplotlib visualization:\n\nfig = plt.figure()\nfig = plt.figure(figsize=plt.figaspect(0.5))\n\nfor m_id in range(30):\n    ax = fig.add_subplot(5,6,m_id+1, projection='3d')\n    ax.scatter(mms[(mms.molecule_name == molecule[m_id])&(mms.atom == 'H')]['x'],\n               mms[(mms.molecule_name == molecule[m_id])&(mms.atom == 'H')]['y'],\n               mms[(mms.molecule_name == molecule[m_id])&(mms.atom == 'H')]['z'],\n               c='w', s=100, linewidths=1, edgecolors='k')\n\n    ax.scatter(mms[(mms.molecule_name == molecule[m_id])&(mms.atom == 'C')]['x'],\n               mms[(mms.molecule_name == molecule[m_id])&(mms.atom == 'C')]['y'],\n               mms[(mms.molecule_name == molecule[m_id])&(mms.atom == 'C')]['z'],\n               c='k', s=100, linewidths=1, edgecolors='k')\n\n    ax.scatter(mms[(mms.molecule_name == molecule[m_id])&(mms.atom == 'O')]['x'],\n               mms[(mms.molecule_name == molecule[m_id])&(mms.atom == 'O')]['y'],\n               mms[(mms.molecule_name == molecule[m_id])&(mms.atom == 'O')]['z'],\n               c='r', s=100, linewidths=1, edgecolors='k')\n\n    ax.scatter(mms[(mms.molecule_name == molecule[m_id])&(mms.atom == 'N')]['x'],\n               mms[(mms.molecule_name == molecule[m_id])&(mms.atom == 'N')]['y'],\n               mms[(mms.molecule_name == molecule[m_id])&(mms.atom == 'N')]['z'],\n               c='b', s=100,  linewidths=1, edgecolors='k')\n\n    ax.scatter(mms[(mms.molecule_name == molecule[m_id])&(mms.atom == 'F')]['x'],\n               mms[(mms.molecule_name == molecule[m_id])&(mms.atom == 'F')]['y'],\n               mms[(mms.molecule_name == molecule[m_id])&(mms.atom == 'F')]['z'],\n               c='orange', s=100,  linewidths=1, edgecolors='k')\n    plt.xticks([])\n    plt.yticks([])\n    plt.grid()\n    plt.title(f'{molecule[m_id]}')\nplt.subplots_adjust(left=.02, right=1.8, top=4)\n\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"mms = mulliken_magnetic_structure\nmolecule = energy_dipole['molecule_name']\n\nm_id = np.random.randint(0,len(molecule))\n\nsymbols = np.array(mms[(mms.molecule_name == molecule[m_id])].atom)\nlocation = np.array(mms[(mms.molecule_name == molecule[m_id])].loc[:,['x','y','z']])\nsystem = Atoms(positions=location, symbols=symbols)\nase.visualize.view(system, viewer=\"x3d\")\n#print(system.get_chemical_formula())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"av_mulliken_charge = mms.groupby('molecule_name').mean()['mulliken_charge']\nplt.hist(av_mulliken_charge, bins=12,color='orange')\nplt.title('Average Mulliken Charge distribution')\nplt.ylabel('Count')\nplt.xlabel('Average Mulliken Charge')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"net_mulliken_charge = mms.groupby('molecule_name').sum()['mulliken_charge']\nplt.hist(net_mulliken_charge, bins=12,color='orange')\nplt.title('Net Mulliken Charge distribution')\nplt.ylabel('Count')\nplt.xlabel('Net Mulliken Charge')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.subplot(121)\nplt.scatter(net_mulliken_charge*1000000, energy_dipole.potential_energy,c='g', s=.4)\nplt.xlabel('Net Mulliken Charge')\nplt.ylabel('Potential Energy')\nplt.title('Scatterplot for Net Mulliken Charge and the Potential Energy')\n\nplt.subplot(122)\nplt.scatter(av_mulliken_charge*1000000, energy_dipole.potential_energy, c='r', s=.4)\nplt.subplots_adjust(left=.01,right=2)\nplt.xlabel('Net Mulliken Charge')\nplt.ylabel('Potential Energy')\nplt.title('Scatterplot for Average Mulliken Charge and the Potential Energy')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"scc = scalar_coupling_contributions\nscc['scalar_coupling_constant'] = scc['fc']+scc['sd']+scc['pso']+scc['dso']","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.pairplot(scc[['fc','sd','pso','dso','type']])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"\ntypes = scc.type.value_counts()\nplt.bar(types.index,types)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sns.distplot(scc.scalar_coupling_constant, color='g', kde=False)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"plt.figure(figsize=(10,10))\nsns.boxplot(x='type', y='scalar_coupling_constant', data=scc)\nplt.xlabel('Type')\nplt.ylabel('Scalar Coupling Constant')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"* <a href=\"cat_boost.csv\"> Download File </a>"}],"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat":4,"nbformat_minor":1}