def write_reaction(self, value_dict):
        con = self.connection or self._connect()
        self._initialize(con)
        cur = con.cursor()

        ase_ids = value_dict['ase_ids']
        energy_corrections = value_dict.get('energy_corrections', {})

        key_list = get_key_list(start_index=1)
        values = [value_dict[key] for key in key_list]

        key_str = get_key_str('reaction', start_index=1)
        value_str = get_value_str(values)

        insert_command = \
            """INSERT INTO reaction ({0})
            VALUES ({1}) RETURNING id;"""\
            .format(key_str, value_str)

        cur.execute(insert_command)
        id = cur.fetchone()[0]

        reaction_system_values = []

        """ Write to reaction_system tables"""
        for name, ase_id in ase_ids.items():
            if name in energy_corrections:
                energy_correction = energy_corrections[name]
            else:
                energy_correction = 0

            reaction_system_values += [tuple([name, energy_correction,
                                              ase_id, id])]

        key_str = get_key_str('reaction_system')
        insert_command = """INSERT INTO reaction_system
        ({0}) VALUES %s ON CONFLICT DO NOTHING;""".format(key_str)

        execute_values(cur=cur, sql=insert_command,
                       argslist=reaction_system_values, page_size=1000)

        if self.connection is None:
            con.commit()
            con.close()

        return id
Write to reaction_system tables