def run_tst_xrs_and_hierarchy():
    # Check if scatterers in xrs are neutral after calling function
    pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_str)
    model = mmtbx.model.manager(model_input=pdb_inp, log=null_out())

    model.neutralize_scatterers()
    xrs = model.get_xray_structure()
    for scatterer in xrs.scatterers():
        assert (scatterer.scattering_type in neutral_atoms_list)

    # Check if pdb_hierarchy has neutral atoms as well
    pdb_str_neutralized = model.model_as_pdb()
    pdb_inp_neutralized = iotbx.pdb.input(source_info=None,
                                          lines=pdb_str_neutralized)
    model_neutralized = mmtbx.model.manager(model_input=pdb_inp_neutralized,
                                            log=null_out())
    xrs_neutralized = model_neutralized.get_xray_structure()
    for scatterer in xrs_neutralized.scatterers():
        assert (scatterer.scattering_type in neutral_atoms_list)
def run_tst_grm_after_neutralize_scatterers():
    # Look at nonbonded interaction CB - OE2 in Glu
    # OE2 has negative charge
    # vdw distance is 2.560 A when OE2 is neutral
    # vdw distance is 2.752 A when OE1 has O1- charge
    pdb_inp = iotbx.pdb.input(source_info=None, lines=pdb_str_2)

    model = mmtbx.model.manager(model_input=pdb_inp,
                                log=null_out(),
                                build_grm=True)
    atoms = model.get_hierarchy().atoms()
    grm = model.get_restraints_manager()
    #  with open('1.geo', 'w') as f:
    #    f.write(model.restraints_as_geo())
    nonbonded_proxies = grm.geometry.pair_proxies().nonbonded_proxies.simple
    for nb_proxy in nonbonded_proxies:
        iseq, jseq = nb_proxy.i_seqs
        if (iseq == 4 and jseq == 8):
            vdw_distance1 = nb_proxy.vdw_distance
            assert (atoms[iseq].name.strip() == 'CB')
            assert (atoms[jseq].name.strip() == 'OE2')

    model = mmtbx.model.manager(model_input=pdb_inp,
                                log=null_out(),
                                build_grm=False)
    model.neutralize_scatterers()
    model.process_input_model(make_restraints=True)
    atoms2 = model.get_hierarchy().atoms()
    grm2 = model.get_restraints_manager()
    #  with open('2.geo', 'w') as f:
    #    f.write(model.restraints_as_geo())
    nonbonded_proxies2 = grm2.geometry.pair_proxies().nonbonded_proxies.simple
    for nb_proxy in nonbonded_proxies2:
        iseq, jseq = nb_proxy.i_seqs
        if (iseq == 4 and jseq == 8):
            vdw_distance2 = nb_proxy.vdw_distance
            assert (atoms2[iseq].name.strip() == 'CB')
            assert (atoms2[jseq].name.strip() == 'OE2')

    assert (vdw_distance1 != vdw_distance2)