diff --git a/iotbx/pdb/hierarchy.py b/iotbx/pdb/hierarchy.py index e06388e09c..9ec6896e28 100644 --- a/iotbx/pdb/hierarchy.py +++ b/iotbx/pdb/hierarchy.py @@ -2056,7 +2056,8 @@ def rename_chain_id(self, old_id, new_id): def remove_atoms(self, fraction): assert fraction>0 and fraction<1. - sel_keep = flex.random_bool(self.atoms_size(), 1-fraction) + n_atoms_to_keep = int(self.atoms_size() * (1-fraction)) + sel_keep = flex.random_selection(self.atoms_size(), n_atoms_to_keep) return self.select(sel_keep) def set_atomic_charge(self, iselection, charge): diff --git a/iotbx/pdb/tst_hierarchy.py b/iotbx/pdb/tst_hierarchy.py index f0b9db7d62..60c7558843 100644 --- a/iotbx/pdb/tst_hierarchy.py +++ b/iotbx/pdb/tst_hierarchy.py @@ -6996,8 +6996,6 @@ def exercise_set_atomic_charge(): assert (ph.atoms()[0].charge == '1-') def exercise_remove_atoms(): - random.seed(1) - flex.set_random_seed(1) pdb_str = """ ATOM 1 N AMET B 37 7.525 5.296 6.399 1.00 10.00 N ATOM 2 CA AMET B 37 6.533 6.338 6.634 1.00 10.00 C @@ -7052,11 +7050,9 @@ def exercise_remove_atoms(): """ pi = pdb.input(source_info=None, lines=pdb_str) ph_in = pi.construct_hierarchy() - s1 = ph_in.atoms_size() + assert ph_in.atoms_size() == 48 ph = ph_in.remove_atoms(fraction=0.1) - s2 = ph.atoms_size() - f = s2*100./s1 - assert f>90 and f<100 + assert ph.atoms_size() == 43 def exercise_set_atomic_charge(): pdb_str = """ diff --git a/mmtbx/regression/tst_pdbtools.py b/mmtbx/regression/tst_pdbtools.py index 2d8ecbb57a..ae78d625af 100644 --- a/mmtbx/regression/tst_pdbtools.py +++ b/mmtbx/regression/tst_pdbtools.py @@ -718,9 +718,6 @@ def exercise_neutralize_scatterers(): assert line1 == line2 def exercise_remove_atoms(): - import random - random.seed(1) - flex.set_random_seed(1) pdb_str = """ ATOM 1 N AMET B 37 7.525 5.296 6.399 1.00 10.00 N ATOM 2 CA AMET B 37 6.533 6.338 6.634 1.00 10.00 C @@ -773,24 +770,18 @@ def exercise_remove_atoms(): TER END """ - pi = iotbx.pdb.input(source_info=None, lines=pdb_str) - ph_in = pi.construct_hierarchy() - s1 = ph_in.atoms_size() - pi.write_pdb_file(file_name="exercise_remove_atoms.pdb") + # Initial size - 48 atoms + with open("exercise_remove_atoms.pdb", 'w') as f: + f.write(pdb_str) cmd = " ".join([ "phenix.pdbtools", "exercise_remove_atoms.pdb", "remove_fraction=0.1"]) print(cmd) run_command(command=cmd, verbose=False) - pi = iotbx.pdb.input(file_name="exercise_remove_atoms_modified.pdb") - ph_in = pi.construct_hierarchy() - s2 = ph_in.atoms_size() - f = s2*100./s1 - # - # UNSTABLE 3x - # - assert f>77 and f<100, f # was getting 79.16, 70.8333 on anaconda t96, + inp = iotbx.pdb.input(file_name="exercise_remove_atoms_modified.pdb") + # removed 5 atoms (~10%). + assert inp.atoms().size() == 43, inp.atoms().size() def exercise_change_of_basis(): with open("tmp_pdbtools_cb_op.pdb", "w") as f: