def test_read_write(self, tmpdir): """Read a topology, write it out, and read in the output again. Writing the topology out should make no change to the topology. """ path = self.processed with tmpdir.as_cwd(): filename1 = 'processed_1.top' filename2 = 'processed_2.top' top1 = TOP(path) top1.write(filename1) # make life harder, write out again top2 = TOP(filename1) top2.write(filename2) top2 = TOP(filename2) attrs1 = [section for section in top1.found_sections if "types" in section] attrs2 = [section for section in top1.found_sections if "types" in section] assert attrs1 == attrs2 #attrs1 = ['atomtypes', 'pairtypes', 'bondtypes', 'constrainttypes', 'angletypes', 'dihedraltypes', 'dihedraltypes', 'cmaptypes'] #attrs1 = ['atomtypes',] for attr in attrs1: attr1 = getattr(top1, attr) attr2 = getattr(top2, attr) assert attr1 == attr2, helper(attr, attr1, attr2)
def test_read_write(self, tmpdir): """Read a topology, write it out, and read in the output again. Writing the topology out should make no change to the topology. """ path = self.processed with tmpdir.as_cwd(): filename1 = 'processed_1.top' filename2 = 'processed_2.top' top1 = TOP(path) top1.write(filename1) # make life harder, write out again top2 = TOP(filename1) top2.write(filename2) top2 = TOP(filename2) attrs1 = [ section for section in top1.found_sections if "types" in section ] attrs2 = [ section for section in top1.found_sections if "types" in section ] assert attrs1 == attrs2 #attrs1 = ['atomtypes', 'pairtypes', 'bondtypes', 'constrainttypes', 'angletypes', 'dihedraltypes', 'dihedraltypes', 'cmaptypes'] #attrs1 = ['atomtypes',] for attr in attrs1: attr1 = getattr(top1, attr) attr2 = getattr(top2, attr) assert attr1 == attr2, helper(attr, attr1, attr2)
# impropertypes = {} for it in top.impropertypes: name = "{0}-{1}-{2}-{3}-{4}".format(it.atype1, it.atype2, it.atype3, it.atype4, it.gromacs['func']) if not name in impropertypes: impropertypes[name] = [] impropertypes[name].append(it) print("Build impropertypes dictionary with {0} entries".format( len(impropertypes))) top.angletypes = scale_angles(mol, angletypes) top.dihedraltypes = scale_dihedrals(mol, dihedraltypes) top.impropertypes = scale_impropers(mol, impropertypes) top.nonbond_params = [] top.cmaptypes = [] atomtypes = {at.atype for at in top.atomtypes} pairtypes = [ pt for pt in top.pairtypes if (pt.atype1 in atomtypes) and (pt.atype2 in atomtypes) ] top.pairtypes = pairtypes # Remove non-default moleculetypes for k in top.dict_molname_mol.keys(): if k in [molname]: continue del top.dict_molname_mol[k] top.write(args.output)
dihedraltypes[name].append(dt) print("Build dihedraltypes dictionary with {0} entries".format(len(dihedraltypes))) # # Build improper dictionary # impropertypes = {} for it in top.impropertypes: name = "{0}-{1}-{2}-{3}-{4}".format(it.atype1, it.atype2, it.atype3, it.atype4, it.gromacs['func']) if not name in impropertypes: impropertypes[name] = [] impropertypes[name].append(it) print("Build impropertypes dictionary with {0} entries".format(len(impropertypes))) top.angletypes = scale_angles(mol, angletypes) top.dihedraltypes = scale_dihedrals(mol, dihedraltypes) top.impropertypes = scale_impropers(mol, impropertypes) top.nonbond_params = [] top.cmaptypes = [] atomtypes = {at.atype for at in top.atomtypes} pairtypes = [pt for pt in top.pairtypes if (pt.atype1 in atomtypes) and (pt.atype2 in atomtypes)] top.pairtypes = pairtypes # Remove non-default moleculetypes for k in top.dict_molname_mol.keys(): if k in [molname]: continue del top.dict_molname_mol[k] top.write(args.output)