<jupyter_start><jupyter_text>Summary - "M1", "M7", "M13" macrocycles In this notebook we summarize the analysis of conformers of the selected macrocycles and their complexes.<jupyter_code>from IPython.display import HTML

HTML('''<script>
code_show=true; 
function code_toggle() {
 if (code_show){
 $('div.input').hide();
 } else {
 $('div.input').show();
 }
 code_show = !code_show
}
$( document ).ready(code_toggle);
</script>
<form action="javascript:code_toggle()"><input type="submit" value="Click here to toggle on/off the raw code."></form>''')
import glob
import py3Dmol

import matplotlib
import matplotlib.pyplot as plt
import seaborn as sns
import pandas as pd
import numpy as np
%matplotlib inline 

from graphviz import Digraph
import pydot

from rdkit import Chem
from rdkit.Chem import AllChem
from rdkit.Chem import Draw
from rdkit.Chem import rdMolAlign
from rdkit.Chem.Draw import IPythonConsole
from rdkit import rdBase
print(rdBase.rdkitVersion)
import os,time
print( time.asctime())
def get_moldict_from_inplist_mm(inplist):
    moldict = {}
    for i, inp in enumerate(inplist):
        mol = Chem.MolFromMolFile(inp)
        name = os.path.basename(os.path.splitext(inp)[0])
        moldict[name] = mol
    return moldict

def get_moldict_from_inplist(inplist):
    moldict = {}
    for i, inp in enumerate(inplist):
        mol = Chem.MolFromMolFile(inp)
        name = os.path.basename(os.path.splitext(inp)[0]).rsplit("_", 5)[0]
        model = "_".join(os.path.basename(os.path.splitext(inp)[0]).rsplit("_", 2)[1:])
        moldict[name] = mol
    return moldict<jupyter_output><empty_output><jupyter_text>Isolated macrocycles   The number of conformers<jupyter_code>def get_moldata_mm(dirname):
    
    list_mm = os.path.join(dirname, 'list_selected_conformers_from_ballon_rdkit')
    
    inps_mm   = []
    inps_mm_b = []
    inps_mm_r = []
    
    with open(list_mm, "r") as f:
        
        lines = f.readlines()
        
        dirs_b  = ["balloon/results_starting_from_crystalsdf/", 
                   "balloon/results_starting_from_crystalsmiles/"]
        
        dirs_r  = ["rdkit/results_crystal_from_sdf/",
                   "rdkit/results_crystal_from_smiles/"]        
               
        for line in lines:    
            for d in dirs_b:
                name = os.path.join(dirname, d, line.strip()+'.sdf')
                if os.path.isfile(name):
                    inps_mm_b.append(name)
            for d in dirs_r:
                name = os.path.join(dirname, d, line.strip()+'.sdf')
                if os.path.isfile(name):
                    inps_mm_r.append(name)

    inps_mm = inps_mm_b + inps_mm_r        
    mol_mm  = get_moldict_from_inplist_mm(inps_mm)
    
    return list_mm, inps_mm, mol_mm, inps_mm_b, inps_mm_r


def get_moldata_dft(dirname):
    
    list_dft = os.path.join(dirname, 'gaussian_results/list_selected_conformers_b97d_631gd')
    inps_dft = []
    
    with open(list_dft, "r") as f:
        lines = f.readlines()
        for line in lines:
            name = os.path.join(dirname,
                                'gaussian_results/optimized_geometries_frequencies_from_outputs',
                                line.strip()+'_gaussian_optimized_geometry_b97d_631gd.sdf')
            inps_dft.append(name)

    mol_dft = get_moldict_from_inplist(inps_dft)
    
    return list_dft, inps_dft, mol_dft

list_m1_mm, inps_m1_mm, mol_m1_mm, inps_m1_mm_b, inps_m1_mm_r      = get_moldata_mm('/home/gosia/work/work_on_gitlab/icho/calcs/m1')
list_m7_mm, inps_m7_mm, mol_m7_mm, inps_m7_mm_b, inps_m7_mm_r      = get_moldata_mm('/home/gosia/work/work_on_gitlab/icho/calcs/m7')
list_m13_mm, inps_m13_mm, mol_m13_mm, inps_m13_mm_b, inps_m13_mm_r = get_moldata_mm('/home/gosia/work/work_on_gitlab/icho/calcs/m13')

list_m1_dft, inps_m1_dft, mol_m1_dft    = get_moldata_dft('/home/gosia/work/work_on_gitlab/icho/calcs/m1')
list_m7_dft, inps_m7_dft, mol_m7_dft    = get_moldata_dft('/home/gosia/work/work_on_gitlab/icho/calcs/m7')
list_m13_dft, inps_m13_dft, mol_m13_dft = get_moldata_dft('/home/gosia/work/work_on_gitlab/icho/calcs/m13')

number_of_conformers_mm = {}
number_of_conformers_mm["m1"] = len(inps_m1_mm)
number_of_conformers_mm["m7"] = len(inps_m7_mm)
number_of_conformers_mm["m13"] = len(inps_m13_mm)

number_of_conformers_dft = {}
number_of_conformers_dft["m1"] = len(inps_m1_dft)
number_of_conformers_dft["m7"] = len(inps_m7_dft)
number_of_conformers_dft["m13"] = len(inps_m13_dft)


number_of_conformers = [number_of_conformers_mm, number_of_conformers_dft]
number_of_conformers = pd.DataFrame(number_of_conformers).transpose().rename(columns={0:'MM', 1:'DFT'})
#number_of_conformers = pd.DataFrame(number_of_conformers).rename(columns={0:'MM', 1:'DFT'})

print(
"The number of conformers generated (gen),\
 selected after the pre-optimization with molecular mechanics (MM),\
 and refined with the density functional theory (DFT)")

number_of_conformers<jupyter_output>The number of conformers generated (gen), selected after the pre-optimization with molecular mechanics (MM), and refined with the density functional theory (DFT)<jupyter_text>The coverage of conformational space<jupyter_code>def plot_line(data, xmin, xmax):
    for i, v in enumerate(data):
        if i == 0:
            ax.hlines(v, xmin, xmax, linestyle='-', color='r', linewidth=1.5)
        else:
            ax.hlines(v, xmin, xmax, linestyle='-', linewidth=1)


def set_style():
    sns.set_context("paper")
    sns.set(font='serif')
    sns.set_style("white", {
        "font.family": "serif",
        "font.serif": ["Times", "Palatino", "serif"]
    })
set_style()
fig, ax = plt.subplots()

ax.set_title("Conformational coverage of the DFT refinement, B97D/631(G)d calculations", fontsize=14)
ax.set_ylabel("Number of structures", fontsize=12)
ax.set_xticks([1.0, 2.5, 4.0])
ax.set_xticklabels(["M1", "M7", "M13"], fontsize=12)



ax.hlines(len(inps_m1), 0.5, 1.5, linestyle='-', color='r', linewidth=1.5)
ax.hlines(len(inps_m7), 2.0, 3.0, linestyle='-', color='r', linewidth=1.5)
ax.hlines(len(inps_m13), 3.5, 4.5, linestyle='-', color='r', linewidth=1.5)


#ax.text(0, 0,
#"E1 = Sum of electronic and zero-point Energies\n\
#E2 = Sum of electronic and thermal Energies\n\
#E3 = Sum of electronic and thermal Enthalpies\n\
#E4 = Sum of electronic and thermal Free Energies")
print(
"The geometrical-similarity network.\
 The nodes denote the structures and the numbering corresponds to the energy values in ascending order\
 ('1' refers to the global minimum).")

from graphviz import Digraph

dot = Digraph(comment='The Round Table')

dot.node('A', 'King Arthur')
dot.node('B', 'Sir Bedevere the Wise')
dot.node('L', 'Sir Lancelot the Brave')

dot.edges(['AB', 'AL'])
dot.edge('B', 'L', constraint='false')

dot<jupyter_output>The geometrical-similarity network. The nodes denote the structures and the numbering corresponds to the energy values in ascending order ('1' refers to the global minimum).<jupyter_text>Thermodynamic properties<jupyter_code>m1_results = "/home/gosia/work/work_on_gitlab/icho/calcs/m1/gaussian_results/FINAL_RESULTS_selected_conformers_thermochemistry_b97d_631gd.csv"
m1_data    = pd.read_csv(m1_results, 
                         skiprows=18, 
                         usecols=[0,5,6,7,8,9,10],
                         delimiter=r"\s+")
m1_data
m7_results = "/home/gosia/work/work_on_gitlab/icho/calcs/m7/gaussian_results/FINAL_RESULTS_selected_conformers_thermochemistry_b97d_631gd.csv"
m7_data    = pd.read_csv(m7_results, 
                         skiprows=18, 
                         usecols=[0,5,6,7,8,9,10],
                         delimiter=r"\s+")
m7_data
m13_results = "/home/gosia/work/work_on_gitlab/icho/calcs/m13/gaussian_results/FINAL_RESULTS_selected_conformers_thermochemistry_b97d_631gd.csv"
m13_data    = pd.read_csv(m13_results, 
                         skiprows=18, 
                         usecols=[0,5,6,7,8,9,10],
                         delimiter=r"\s+")
m13_data
# functions used for plots
def plot_line(ax, data, xmin, xmax):
    for i, v in enumerate(data):
        # data is sorted; the first element corresponds to the lowest energy; we'll plot it in red
        if i == 0:
            ax.hlines(v, xmin, xmax, linestyle='-', color='r', linewidth=1.5)
        else:
            ax.hlines(v, xmin, xmax, linestyle='-', linewidth=1)

def set_style():
    sns.set_context("paper")
    sns.set(font='serif')
    sns.set_style("white", {
        "font.family": "serif",
        "font.serif": ["Times", "Palatino", "serif"]
    })
# plot - all macrocycles side by side
set_style()
fig, (ax1, ax7, ax13) = plt.subplots(1,3,sharey=True,figsize=(15,5))

fig.suptitle("Relative energies of selected conformers", fontsize=16)
ax1.set_title("M1")
ax7.set_title("M7")
ax13.set_title("M13")

ax1.set_ylabel("Relative energies [kcal/mol]", fontsize=12)

for ax in [ax1, ax7, ax13]:
    ax.set_xticks([0.0, 1.5, 3.0, 4.5])
    ax.set_xticklabels(["E1", "E2", "E3", "E4"], fontsize=12)


# plot
# m1
plot_line(ax1, m1_data["E1-E1(min)[kcal/mol]"], -0.5, 0.5)
plot_line(ax1, m1_data["E2-E2(min)[kcal/mol]"],  1.0, 2.0)
plot_line(ax1, m1_data["E3-E3(min)[kcal/mol]"],  2.5, 3.5)
plot_line(ax1, m1_data["E4-E4(min)[kcal/mol]"],  4.0, 5.0)

# m7

# m13


ax1.text(0, -15,
"E1 = Sum of electronic and zero-point Energies\n\
E2 = Sum of electronic and thermal Energies\n\
E3 = Sum of electronic and thermal Enthalpies\n\
E4 = Sum of electronic and thermal Free Energies")<jupyter_output><empty_output><jupyter_text>M1  Energy landscapes<jupyter_code>f_m1 = "/home/gosia/work/work_on_gitlab/icho/calcs/m1/gaussian_results/FINAL_RESULTS_selected_conformers_thermochemistry_b97d_631gd.csv"
m1_data = pd.read_csv(f_m1, 
                      skiprows=18, 
                      usecols=[0,5,6,7,8,9,10],
                      delimiter=r"\s+")

f_m1_h2o = "/home/gosia/work/work_on_gitlab/icho/calcs/m1-h2o/gaussian_results/FINAL_RESULTS_selected_conformers_thermochemistry_b97d_631gd.csv"
m1_h2o_data = pd.read_csv(f_m1_h2o, 
                      skiprows=18, 
                      usecols=[0,5,6,7,8,9,10],
                      delimiter=r"\s+")

f_m1_2h2o = "/home/gosia/work/work_on_gitlab/icho/calcs/m1-2h2o/gaussian_results/FINAL_RESULTS_selected_conformers_thermochemistry_b97d_631gd.csv"
m1_2h2o_data = pd.read_csv(f_m1_2h2o, 
                      skiprows=18, 
                      usecols=[0,5,6,7,8,9,10],
                      delimiter=r"\s+")

f_m1_h2o_dmso = "/home/gosia/work/work_on_gitlab/icho/calcs/m1-h2o-dmso/gaussian_results/FINAL_RESULTS_selected_conformers_thermochemistry_b97d_631gd.csv"
m1_h2o_dmso_data = pd.read_csv(f_m1_h2o_dmso, 
                      skiprows=18, 
                      usecols=[0,5,6,7,8,9,10],
                      delimiter=r"\s+")

f_m1_2h2o_dmso = "/home/gosia/work/work_on_gitlab/icho/calcs/m1-2h2o-dmso/gaussian_results/FINAL_RESULTS_selected_conformers_thermochemistry_b97d_631gd.csv"
m1_2h2o_dmso_data = pd.read_csv(f_m1_2h2o_dmso, 
                      skiprows=18, 
                      usecols=[0,5,6,7,8,9,10],
                      delimiter=r"\s+")

f_m1_h2o_methanol = "/home/gosia/work/work_on_gitlab/icho/calcs/m1-h2o-methanol/gaussian_results/FINAL_RESULTS_selected_conformers_thermochemistry_b97d_631gd.csv"
m1_h2o_methanol_data = pd.read_csv(f_m1_h2o_methanol, 
                      skiprows=18, 
                      usecols=[0,5,6,7,8,9,10],
                      delimiter=r"\s+")

f_m1_2h2o_methanol = "/home/gosia/work/work_on_gitlab/icho/calcs/m1-2h2o-methanol/gaussian_results/FINAL_RESULTS_selected_conformers_thermochemistry_b97d_631gd.csv"
m1_2h2o_methanol_data = pd.read_csv(f_m1_2h2o_methanol, 
                      skiprows=18, 
                      usecols=[0,5,6,7,8,9,10],
                      delimiter=r"\s+")<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12809045650156106, 'fraction_numerical': 0.03881528984895789, 'mean_word_length': 3.381515711645102, 'pattern_counts': {'":': 4, '<': 24, '<?xml version=': 0, '>': 24, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '391050', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 4948, 'n_tokens_neox': 4663, 'n_words': 741, 'path': 'summary_m1_m7_m13.ipynb', 'repo_name': 'gosiao/icho-notebooks', 'size': '11851'}