def tune_geometry(graph, mol, unit_cell=None, verbose=False):
N = len(graph.numbers)<EOL>from molmod.minimizer import Minimizer, ConjugateGradient,NewtonLineSearch, ConvergenceCondition, StopLossCondition<EOL>search_direction = ConjugateGradient()<EOL>line_search = NewtonLineSearch()<EOL>convergence = ConvergenceCondition(grad_rms=<NUM_LIT>, step_rms=<NUM_LIT>)<EOL>stop_loss = StopLossCondition(max_iter=<NUM_LIT>, fun_margin=<NUM_LIT:1.0>)<EOL>ff = ToyFF(graph, unit_cell)<EOL>x_init = mol.coordinates.ravel()<EOL>ff.dm_reci = <NUM_LIT><EOL>ff.bond_quad = <NUM_LIT:1.0><EOL>minimizer = Minimizer(x_init, ff, search_direction, line_search, convergence, stop_loss, anagrad=True, verbose=verbose)<EOL>x_init = minimizer.x<EOL>ff.bond_quad = <NUM_LIT:0.0><EOL>ff.bond_hyper = <NUM_LIT:1.0><EOL>ff.span_quad = <NUM_LIT:1.0><EOL>minimizer = Minimizer(x_init, ff, search_direction, line_search, convergence, stop_loss, anagrad=True, verbose=verbose)<EOL>x_init = minimizer.x<EOL>x_opt = x_init<EOL>mol = Molecule(graph.numbers, x_opt.reshape((N, <NUM_LIT:3>)))<EOL>return mol<EOL>
Fine tune a molecular geometry, starting from a (very) poor guess of
       the initial geometry.

       Do not expect all details to be in perfect condition. A subsequent
       optimization with a more accurate level of theory is at least advisable.

       Arguments:
        | ``graph``  --  The molecular graph of the system, see
                         :class:molmod.molecular_graphs.MolecularGraph
        | ``mol``  --  A :class:molmod.molecules.Molecule class with the initial
                       guess of the coordinates

       Optional argument:
        | ``unit_cell``  --  periodic boundry conditions, see
                             :class:`molmod.unit_cells.UnitCell`
        | ``verbose``  --  Show optimizer progress when True