Beispiel #1
0
def combine_holders(
    holder1,
    holder2,
    holder1_bond_path=".tmp/bonds.dat",
    holder2_bond_path=".tmp/bonds.dat",
    out_path=".tmp/bonds.dat",
    vector=np.zeros(3),
    atom_link_list=[],
    opt_ids=False,
):
    holder1, atom_ids1 = reassign_atom_ids(holder1)
    bonds1 = readbond(holder1_bond_path)
    holder2, atom_ids2 = reassign_atom_ids(holder2, start_id=holder1.num_atoms)
    bonds2 = readbond(holder2_bond_path)

    atom_id = 0
    holder_new = createHolder(holder1.num_atoms + holder2.num_atoms)
    for i in sorted(holder1.pos):
        holder_new.pos[atom_id] = holder1.pos[i]
        holder_new.el_names[atom_id] = holder1.el_names[i]
        holder_new.atom_types[atom_id] = holder1.atom_types[i]
        atom_id += 1
    for i in sorted(holder2.pos):
        holder_new.pos[atom_id] = holder2.pos[i] + vector
        holder_new.el_names[atom_id] = holder2.el_names[i]
        holder_new.atom_types[atom_id] = holder2.atom_types[i]
        atom_id += 1

    bonds_file = open(out_path, "w")
    bonds_file.write("BONDS\n")
    bonds_file.write("\n")
    bond_id = 1
    for bond in bonds1:
        atom1 = bond[0]
        atom2 = bond[1]
        bonds_file.write("%d 1 %d %d\n" % (bond_id, atom_ids1[atom1], atom_ids1[atom2]))
        bond_id += 1
    for bond in bonds2:
        atom1 = bond[0]
        atom2 = bond[1]
        bonds_file.write("%d 1 %d %d\n" % (bond_id, atom_ids2[atom1], atom_ids2[atom2]))
        bond_id += 1
    if atom_link_list:
        for link_list in atom_link_list:
            bonds_file.write(
                "%d 1 %d %d\n"
                % (bond_id, atom_ids1[link_list[0]], atom_ids2[link_list[1]])
            )
    bonds_file.close()

    if opt_ids:
        return holder_new, atom_ids1, atom_ids2
    else:
        return holder_new
Beispiel #2
0
def reassign_atom_ids(holder, start_id=0):
    atom_ids = {}
    atom_id = 0
    holder_new = createHolder(holder.num_atoms)
    for i in sorted(holder.pos):
        holder_new.pos[atom_id] = holder.pos[i]
        holder_new.el_names[atom_id] = holder.el_names[i]
        holder_new.atom_types[atom_id] = holder.atom_types[i]
        atom_id += 1
        atom_ids[i + 1] = atom_id + start_id
    return holder_new, atom_ids
Beispiel #3
0
    def create_centered_chain(self):
        holder = createHolder(self.holder.num_atoms)

        array = np.array([self.a / 2, self.b / 2, 0])
        chain_cluster = Cluster()

        for atom in self.holder.pos:
            chain_cluster.add_particle(Sphere(self.holder.pos[atom]))
            holder.el_names[atom] = self.holder.el_names[atom]

        translator = Translator()
        chain_cluster.move(translator, array=array)

        for i in range(holder.num_atoms):
            holder.pos[i] = chain_cluster.particles[i].center

        return holder
Beispiel #4
0
def combine_holders(
    holder1,
    holder2,
    holder1_bond_path=".tmp/bonds.dat",
    holder2_bond_path=".tmp/bonds.dat",
    out_path=".tmp/bonds.dat",
):
    holder1, atom_ids1 = reassign_atom_ids(holder1)
    bonds1 = readbond(holder1_bond_path)
    holder2, atom_ids2 = reassign_atom_ids(holder2, start_id=holder1.num_atoms)
    bonds2 = readbond(holder2_bond_path)

    atom_id = 0
    holder_new = createHolder(holder1.num_atoms + holder2.num_atoms)
    for i in sorted(holder1.pos):
        holder_new.pos[atom_id] = holder1.pos[i]
        holder_new.el_names[atom_id] = holder1.el_names[i]
        holder_new.atom_types[atom_id] = holder1.atom_types[i]
        atom_id += 1
    for i in sorted(holder2.pos):
        holder_new.pos[atom_id] = holder2.pos[i]
        holder_new.el_names[atom_id] = holder2.el_names[i]
        holder_new.atom_types[atom_id] = holder2.atom_types[i]
        atom_id += 1

    bonds_file = open(out_path, "w")
    bonds_file.write("BONDS\n")
    bonds_file.write("\n")
    bond_id = 1
    for bond in bonds1:
        atom1 = bond[0]
        atom2 = bond[1]
        bonds_file.write("%d 1 %d %d\n" %
                         (bond_id, atom_ids1[atom1], atom_ids1[atom2]))
        bond_id += 1
    for bond in bonds2:
        atom1 = bond[0]
        atom2 = bond[1]
        bonds_file.write("%d 1 %d %d\n" %
                         (bond_id, atom_ids2[atom1], atom_ids2[atom2]))
        bond_id += 1
    bonds_file.close()

    return holder_new