def run_polymod(infile, validate_bond=False): while not success_run_polymod(infile): pass if validate_bond: h = readPDB(".tmp/chains_unwrapped.pdb") while not validate_bonds(h.pos, ".tmp/bonds.dat"): while not success_run_polymod(infile): pass h = readPDB(".tmp/chains_unwrapped.pdb")
def validate_coords(coords_path, bond_path): holder = readPDB(coords_path) bonds = readbond(bond_path) if use_ovito: pipeline = import_file(coords_path) types = pipeline.source.data.particles.particle_types for i in range(holder.num_atoms): for j in range(i + 1, holder.num_atoms): if ([i + 1, j + 1] not in bonds) and ([j + 1, i + 1] not in bonds): if np.linalg.norm(holder.pos[i] - holder.pos[j]) <= ( types.type_by_name(holder.el_names[i]).radius + types.type_by_name(holder.el_names[j]).radius): return False else: for i in range(holder.num_atoms): for j in range(i + 1, holder.num_atoms): if ([i + 1, j + 1] not in bonds) and ([j + 1, i + 1] not in bonds): if (holder.el_names[i] in atomic_radii) and (holder.el_names[j] in atomic_radii): if np.linalg.norm(holder.pos[i] - holder.pos[j]) <= ( atomic_radii[holder.el_names[i]] + atomic_radii[holder.el_names[j]]): return False else: if np.linalg.norm(holder.pos[i] - holder.pos[j]) < 1.5: return False return True
def build_helix(self): self.find_configurations() print("Total %d possible configurations found for Helice %s" % (len(self.configurations), self.helice)) config_success = 0 for config_index in self.configurations: print("Try Configuration", config_index) # Build polymod input file self.input_polymod(".tmp/run_polymod.txt", config_index) # input_polymod('run_polymod.txt',monomer_path,helice,backbone_atoms=backbone_atoms,tacticity=tacticity,side_atom=side_atom,chiriality=chiriality,num_monomers=num_monomers) # input_polymod('run_polymod.txt',monomer_path, helice, tacticity, chiriality, num_monomers=num_monomers) # Run polymod run_polymod(".tmp/run_polymod.txt", validate_bond=True) if validate_coords(".tmp/chains_unwrapped.pdb", ".tmp/bonds.dat"): config_success = 1 print("Success for Configuration", config_index) break else: print("Fail for Configuration", config_index) if config_success: return readPDB(".tmp/chains_unwrapped.pdb") else: raise Exception( "Unable to generate a successful Helice_%s configuration with %s due to unavoided overlap of atoms." % (self.helice, self.polymer_type.name))
def custom_build_helix(polymer_type, num_monomers, infinite): unit_holder = readPDB(polymer_type.path) symbols, coords = open_pdb(polymer_type.path) # noqa: F405 key_atoms = polymer_type.backbone_atoms vector = unit_holder.pos[key_atoms[1] - 1] - unit_holder.pos[key_atoms[0] - 1] unit_distance = np.linalg.norm(vector) unit_vector = vector / unit_distance unit_head_atom = key_atoms[0] unit_head_append_atoms = polymer_type.append_atoms[unit_head_atom] unit_tail_atom = key_atoms[1] unit_tail_append_atoms = polymer_type.append_atoms[unit_tail_atom] if infinite: for i in range(num_monomers): if i: holder = build_bonds_data( holder, # noqa: F405 in_path=".tmp/bonds.dat", atom_remove_list=tail_append_atoms, # noqa: F405 out_path=".tmp/bonds.dat", ) atom_link_list = [] for atom in link_atoms: # noqa: F405 atom_link_list.append([tail_atom, atom]) # noqa: F405 holder = combine_holders( holder, unit_holder, holder1_bond_path=".tmp/bonds.dat", holder2_bond_path=".tmp/unit_bonds.dat", out_path=".tmp/bonds.dat", vector=i * vector, atom_link_list=atom_link_list, ) tail_atom += unit_holder.num_atoms - num_tail_append_atoms # noqa: F405 for index in range(num_tail_append_atoms): # noqa: F405 tail_append_atoms[index] += ( # noqa: F405 unit_holder.num_atoms - num_tail_append_atoms # noqa: F405 ) # noqa: F405 else: holder = copy.deepcopy(unit_holder) unit_holder, link_atoms = find_link_atoms( unit_holder, unit_head_atom, unit_head_append_atoms ) # head_atom = unit_head_atom head_append_atoms = copy.copy(unit_head_append_atoms) # noqa: F841 tail_atom = unit_tail_atom # noqa: F841 tail_append_atoms = copy.copy(unit_tail_append_atoms) # noqa: F841 num_tail_append_atoms = len(tail_append_atoms) else: for i in range(num_monomers): if i: holder = build_bonds_data( holder, in_path=".tmp/bonds.dat", atom_remove_list=tail_append_atoms, out_path=".tmp/bonds.dat", ) atom_link_list = [] for atom in link_atoms: atom_link_list.append([tail_atom, atom]) holder, atom_ids1, atom_ids2 = combine_holders( holder, unit_holder, holder1_bond_path=".tmp/bonds.dat", holder2_bond_path=".tmp/unit_bonds.dat", out_path=".tmp/bonds.dat", vector=i * vector, atom_link_list=atom_link_list, opt_ids=True, ) tail_atom = atom_ids2[ unit_tail_atom ] # -num_tail_append_atoms # noqa: F405 for index in range(num_tail_append_atoms): # noqa: F405 tail_append_atoms[index] = atom_ids2[ unit_tail_append_atoms[index] ] # noqa: F405 else: holder = copy.deepcopy(unit_holder) unit_holder, link_atoms = find_link_atoms( unit_holder, unit_head_atom, unit_head_append_atoms ) # head_atom = unit_head_atom head_append_atoms = copy.copy(unit_head_append_atoms) # noqa: F841 tail_atom = unit_tail_atom # noqa: F841 tail_append_atoms = copy.copy(unit_tail_append_atoms) # noqa: F841 num_tail_append_atoms = len(tail_append_atoms) return holder, unit_vector, unit_distance
def identify_backbone_path(self, find_inverse_path=False): h = readPDB(self.path) backbone_el = [h.el_names[i - 1] for i in self.backbone_atoms] if (find_inverse_path and (not self.side_atom) and backbone_el == backbone_el[::-1]): raise Exception( "Polymer type %s does not have defects for head to head or tail to tail connections" % (self.name)) bonds = build_bond_list(h.pos, elements=h.el_names) center_head = self.backbone_atoms[0] center_tail = self.backbone_atoms[-1] if (self.side_atom and ((center_tail - 1, self.side_atom - 1) not in bonds) and ((self.side_atom - 1, center_tail - 1) not in bonds)): raise ValueError("side atom must connect to tail backbone atom") head_atoms = [] tail_atoms = [] for key in bonds: atom1, atom2 = key if self.side_atom and (self.side_atom - 1 in [atom1, atom2]): continue elif center_head - 1 == atom1: if not center_tail - 1 == atom2: head_atoms.append(atom2 + 1) elif center_head - 1 == atom2: if not center_tail - 1 == atom1: head_atoms.append(atom1 + 1) elif center_tail - 1 == atom1: if not center_head - 1 == atom2: tail_atoms.append(atom2 + 1) elif center_tail - 1 == atom2: if not center_head - 1 == atom1: tail_atoms.append(atom1 + 1) backbones = {} for tail in tail_atoms: for head in head_atoms: tail_torsion = get_tail_torsion(self.path, head, tail) while tail_torsion < 0: tail_torsion += 360 while tail_torsion >= 360: tail_torsion -= 360 tail_torsion = (60 if 0 <= tail_torsion < 120 else 180 if 120 <= tail_torsion < 240 else 300) m_name = "h_m" + str(tail) + "T" + str(tail_torsion) backbones[m_name] = Backbone(m_name, self.path, head, tail, tail_torsion) if find_inverse_path: tail_torsion = get_tail_torsion(self.path, tail, head) while tail_torsion < 0: tail_torsion += 360 while tail_torsion >= 360: tail_torsion -= 360 tail_torsion = (60 if 0 <= tail_torsion < 120 else 180 if 120 <= tail_torsion < 240 else 300) m_name = "t_m" + str(tail) + "T" + str(tail_torsion) backbones[m_name] = Backbone(m_name, self.path, tail, head, tail_torsion) return backbones