Ejemplo n.º 1
0
def make_fake_topology(n_atoms):
    '''make fake Topology, just for writing xyz array to supported formats
    (netcdf, dcd, trr, ...)

    >>> import pytraj as pt
    >>> top = pt.tools.make_fake_topology(100)
    >>> top.n_atoms
    100
    >>> isinstance(top, pt.Topology)
    True
    >>> import numpy as np
    >>> xyz = np.random.rand(10*100*3).reshape(10, 100, 3)
    >>> traj0 = pt.Trajectory(xyz=xyz, top=top)
    >>> pt.write_traj('output/test.nc', traj0, overwrite=True)
    >>> traj = pt.iterload('output/test.nc', top=top)
    >>> traj.n_atoms
    100
    '''
    from pytraj import Atom, Residue, Topology

    top = Topology()

    for _ in range(n_atoms):
        atom = Atom(name='X', type='X', charge=0., mass=0., resid=0)
        residue = Residue('Y', 0)
        top.add_atom(atom, residue)
    return top
Ejemplo n.º 2
0
def make_fake_topology(n_atoms):
    '''make fake Topology, just for writing xyz array to supported formats
    (netcdf, dcd, trr, ...)

    >>> import pytraj as pt
    >>> top = pt.tools.make_fake_topology(100)
    >>> top.n_atoms
    100
    >>> isinstance(top, pt.Topology)
    True
    >>> import numpy as np
    >>> xyz = np.random.rand(10*100*3).reshape(10, 100, 3)
    >>> traj0 = pt.Trajectory(xyz=xyz, top=top)
    >>> pt.write_traj('output/test.nc', traj0, overwrite=True)
    >>> traj = pt.iterload('output/test.nc', top=top)
    >>> traj.n_atoms
    100
    '''
    from pytraj import Atom, Residue, Topology

    top = Topology()

    for _ in range(n_atoms):
        atom = Atom(name='X', type='X', charge=0., mass=0., resid=0)
        residue = Residue('Y', 0)
        top.add_atom(atom, residue)
    return top
Ejemplo n.º 3
0
def _load_Topology(filename):
    from pytraj import Topology, ParmFile
    top = Topology()
    parm = ParmFile()
    parm.read(filename, top)
    return top
Ejemplo n.º 4
0
 def test_empty_top(self):
     top = Topology()
     assert top.is_empty() == True
     top = pt.load_topology(tc5b_top)
     assert top.is_empty() == False
Ejemplo n.º 5
0
 def test_empty_top(self):
     top = Topology()
     assert top.is_empty() == True
     filename = "./data/Tc5b.top"
     top = pt.load_topology(filename)
     assert top.is_empty() == False
Ejemplo n.º 6
0
 def test_empty_top(self):
     top = Topology()
     assert top.is_empty() == True
     filename = "./data/Tc5b.top"
     top = pt.load_topology(filename)
     assert top.is_empty() == False
Ejemplo n.º 7
0
def to_pytraj_Topology(item, atom_indices='all', check=True):

    if check:

        digest_item(item, 'molsysmt.Topology')
        atom_indices = digest_atom_indices(atom_indices)

    try:
        from pytraj import Topology
        from pytraj import Atom as pytraj_atom, Residue as pytraj_residue
    except:
        raise LibraryNotFound('pytraj')

    from molsysmt.physico_chemical_properties import mass as get_mass
    from molsysmt.physico_chemical_properties import charge as get_charge
    from molsysmt import puw

    n_atoms = item.atoms_dataframe.shape[0]

    atom_index_array = item.atoms_dataframe["atom_index"].to_numpy()
    atom_name_array = item.atoms_dataframe["atom_name"].to_numpy()
    atom_id_array = item.atoms_dataframe["atom_id"].to_numpy()
    atom_type_array = item.atoms_dataframe["atom_type"].to_numpy()

    group_index_array = item.atoms_dataframe["group_index"].to_numpy()
    group_name_array = item.atoms_dataframe["group_name"].to_numpy()
    group_id_array = item.atoms_dataframe["group_id"].to_numpy()
    group_type_array = item.atoms_dataframe["group_type"].to_numpy()

    chain_index_array = item.atoms_dataframe["chain_index"].to_numpy()
    chain_name_array = item.atoms_dataframe["chain_name"].to_numpy()
    chain_id_array = item.atoms_dataframe["chain_id"].to_numpy()
    chain_type_array = item.atoms_dataframe["chain_type"].to_numpy()

    bonds_atom1 = item.bonds_dataframe["atom1_index"].to_numpy()
    bonds_atom2 = item.bonds_dataframe["atom2_index"].to_numpy()

    mass_atom_array = puw.get_value(get_mass(item))
    try:
        charge_atom_array = get_charge(molecular_system)
    except:
        charge_atom_array = np.zeros(shape=[n_atoms])

    tmp_item = Topology()

    former_group_index = -1

    list_new_atoms = []

    for ii in range(n_atoms):

        atom_index = atom_index_array[ii]
        atom_name = atom_name_array[ii]
        atom_id = atom_id_array[ii]
        atom_type = atom_type_array[ii]
        atom_charge = atom_charge_array[ii]
        atom_mass = atom_mass_array[ii]

        group_index = group_index_array[ii]
        chain_index = chain_index_array[ii]

        new_group = (former_group_index != group_index)

        if new_group:
            residue_name = group_name_array[ii]
            residue_id = group_id_array[ii]
            residue = pytraj_residue(residue_name,
                                     resid=group_index,
                                     icode=residue_id,
                                     chainID=chain_index)
            former_group_index = group_index

        atom = pytraj_atom(name=atom_name,
                           type=atom_type,
                           resid=group_index,
                           mass=atom_mass,
                           charge=atom_charge)

        list_new_atoms.append(atom)

        tmp_item.add_atom(atom, residue)

    bonds = np.column_stack(bonds_atom1, bonds_atom2)
    tmp_item.add_bonds(bonds)

    return tmp_item