def main():
    args = _args().parse_args()

    top = files_io.GROMACSTopologyFile(args.top)
    top.read()

    # We need graph to get the connected components.
    g = nx.Graph()
    g.add_nodes_from(top.atoms.keys())
    g.add_edges_from(top.bonds.keys())
    print('Number of nodes: {}'.format(g.number_of_nodes()))
    print('Number of edges: {}'.format(g.number_of_edges()))

    connected_components = list(nx.connected_component_subgraphs(g))
    print('Number of chains: {}'.format(len(connected_components)))
    chain_idx = 0
    chain_names = []
    chain_size = []
    with open(args.output_index, 'w') as out_index:
        for s in connected_components:
            if s.number_of_nodes() > 3:  # Do not put monomers into the groups
                nodes = sorted(s.nodes())
                out_index.write('[ chain_{} ]\n'.format(chain_idx))
                chain_names.append('chain_{}'.format(chain_idx))
                out_index.write(' '.join(map(str, nodes)))
                out_index.write('\n\n')
                chain_size.append(s.number_of_nodes())
                chain_idx += 1

    cmds = args.polystat_cmd.split() + [
        '-f', args.trj, '-n', args.output_index, '-b', '5000'
    ]
    output_file = '{}_ee_rg.csv'.format(args.output_prefix)
    with open(output_file, 'w') as outd:
        outd.write('# chidx ee rg n\n')
        p = mp.Pool(args.nt)
        _compute = functools.partial(compute, cmds)
        out_data = p.map(_compute, chain_names)
        for chidx, data in enumerate(out_data):
            if data[0]:
                try:
                    re_findall = re.findall(r'[0-9]+\.[0-9]+', data[0])
                    ee, rg = map(float, re_findall)
                    outd.write('{} {:.4f} {:.4f} {:.4f}\n'.format(
                        chidx, ee, rg, chain_size[chidx]))
                except ValueError:
                    print(data, re_findall)
    print('Saved {}'.format(output_file))
def main():
    args = _args().parse_args()

    top = files_io.GROMACSTopologyFile(args.in_top)
    top.read()

    water_molecules = [x for x in sorted(top.atoms) if top.atoms[x].chain_name == args.mol_name]

    atom_ids = [(water_molecules[i:i+args.mol_size], mol_id)
                for mol_id, i in enumerate(range(0, len(water_molecules), args.mol_size))]

    p = mp.Pool(args.nt)

    _calc_msd = functools.partial(calc_msd, args.trj, args.output_prefix)
    mol_msd_data = p.map(_calc_msd, atom_ids)

    np.savetxt('{}{}'.format(args.output_prefix, args.output), mol_msd_data, header='mol_id D +/-')
def main():
    args = _args().parse_args()

    top = files_io.GROMACSTopologyFile(args.top)
    top.read()

    # We need graph to get the connected components.
    g = nx.Graph()
    g.add_nodes_from(top.atoms.keys())
    g.add_edges_from(top.bonds.keys())
    print('Number of nodes: {}'.format(g.number_of_nodes()))
    print('Number of edges: {}'.format(g.number_of_edges()))

    connected_components = list(nx.connected_component_subgraphs(g))
    print('Number of chains: {}'.format(len(connected_components)))
    chain_idx = 0
    with open(args.output_index, 'w') as out_index:
        for s in connected_components:
            if s.number_of_nodes() > 3:  # Do not put monomers into the groups
                nodes = sorted(s.nodes())
                out_index.write('[ chain_{} ]\n'.format(chain_idx))
                out_index.write(' '.join(map(str, nodes)))
                out_index.write('\n\n')
                chain_idx += 1
Exemple #4
0
def main():
    args = _args()

    top = args.top
    conf = args.conf
    h5 = args.h5

    top = files_io.GROMACSTopologyFile(top)
    top.read()

    conf = files_io.GROFile(conf)
    conf.read()

    h5 = h5py.File(h5, 'r')

    species2typename = {
        0: 'D',
        1: 'A',
        2: 'B',
        3: 'C',
        4: 'E',
        5: 'W',
        6: 'Z',
        7: 'X'
    }
    species = h5['/particles/atoms/species/value'][-1]

    chain_names = {
        0: 'DIO',
        4: 'DIO',
        1: 'TER',
        2: 'TER',
        3: 'TER',
        5: 'H2O',
        6: 'H2O',
        7: 'DUM'
    }

    names = {
        'DIO': {
            ('D', ): ['D1'],
            ('E', ): ['E1'],
        },
        'TER': {
            ('A', 'B', 'A'): ['A1', 'B1', 'A2'],
            ('A', 'B', 'C'): ['A1', 'B1', 'Q2'],
            ('C', 'B', 'A'): ['Q1', 'B1', 'A2'],
            ('C', 'B', 'C'): ['Q1', 'B1', 'Q2']
        },
        'H2O': {
            ('W', ): ['W1'],
            ('Z', ): ['Z1']
        }
    }

    # First set correct type
    last_chain_idx = 0
    chain_id = 1
    old2new = {}
    atidx = 1
    new_atoms = {}
    conf_new_atoms = {}
    for at_id, sp in enumerate(species, 1):
        if at_id not in top.atoms:
            continue
        old2new[at_id] = atidx
        at_data = copy.copy(top.atoms[at_id])
        new_atoms[atidx] = at_data
        at_data.atom_type = species2typename[sp]
        at_data.atom_id = atidx
        if top.atoms[at_id].chain_idx != last_chain_idx:
            last_chain_idx = top.atoms[at_id].chain_idx
            at_data.chain_idx = chain_id
            chain_id += 1
        at_data.chain_name = chain_names[sp]
        conf_new_atoms[atidx] = conf.atoms[at_id]._replace(
            chain_name=chain_names[sp], chain_idx=chain_id, atom_id=atidx)
        atidx += 1

    atom_list = [new_atoms[x] for x in sorted(new_atoms)]

    # Set names
    at_id = 0
    total_num = len(atom_list)
    while at_id < total_num:
        at_data = atom_list[at_id]
        name_seq = names[at_data.chain_name]
        window_size = len(name_seq.keys()[0])
        at_type_seq = tuple(x.atom_type
                            for x in atom_list[at_id:at_id + window_size])
        for i, x in enumerate(atom_list[at_id:at_id + window_size]):
            x.name = name_seq[at_type_seq][i]
            new_atoms[x.atom_id].atom_name = x.name
            conf_new_atoms[x.atom_id] = conf_new_atoms[x.atom_id]._replace(
                name=x.name)
        at_id += window_size

    top.atoms = new_atoms
    conf.atoms = conf_new_atoms

    top.write('new_{}'.format(sys.argv[1]), force=True)
    conf.write('new_{}'.format(sys.argv[2]), force=True)
def main():
    args = _args().parse_args()

    top = files_io.GROMACSTopologyFile(args.top)
    top.read()

    # Remove sections
    top.atomstate = {}
    top.nonbonded_params = {}

    # Add missing bondtypes
    if 'E' not in top.bondtypes:
        top.bondtypes['E'] = {'C': {'func': 1, 'params': ['0.256395', '27244.6']}}

    if 'C' not in top.angletypes:
        top.angletypes['C'] = {}
    if 'B' not in top.angletypes['C']:
        top.angletypes['C']['B'] = {}
    top.angletypes['C']['B']['C'] = {'func': 8, 'params': ['2', '1.0']}
    top.angletypes[('C', 'B', 'C')] = {'func': 8, 'params': ['2', '1.0']}

    if 'E' not in top.dihedraltypes:
        top.dihedraltypes['E'] = {}
    if 'C' not in top.dihedraltypes['E']:
        top.dihedraltypes['E']['C'] = {}
    if 'B' not in top.dihedraltypes['E']['C']:
        top.dihedraltypes['E']['C']['B'] = {}
    top.dihedraltypes['E']['C']['B']['C'] = {'func': 8, 'params': ['0', '1.0']}
    top.dihedraltypes[('E', 'C', 'B', 'C')] = {'func': 8, 'params': ['0', '1.0']}

    for k in top.angles:
        t = tuple([top.atoms[x].atom_type for x in k])
        angletype = top.angletypes[t]
        if not ' '.join(top.angles[k]).split(';')[0].strip():
            top.angles[k] = [str(angletype['func'])] + angletype['params'] + top.angles[k]

    for k in top.dihedrals:
        t = tuple([top.atoms[x].atom_type for x in k])
        dihedraltype = top.dihedraltypes[t]
        if not ' '.join(top.dihedrals[k]).split(';')[0].strip():
            top.dihedrals[k] = [str(dihedraltype['func'])] + dihedraltype['params'] + top.dihedrals[k]

    conf = files_io.GROFile(args.conf)
    conf.read()

    h5 = h5py.File(args.h5, 'r')

    species2typename = {0: 'D', 1: 'A', 2: 'B', 3: 'C', 4: 'E', 5: 'W', 6: 'Z', 7: 'X'}
    species = h5['/particles/atoms/species/value'][-1]

    chain_names = {
        0: 'DIO',
        4: 'DIO',
        1: 'TER',
        2: 'TER',
        3: 'TER',
        5: 'H2O',
        6: 'H2O',
        7: 'DUM'
    }

    names = {
        'DIO': {('D',): ['D1'],
                ('E',): ['E1'],
            },
        'TER': {('A', 'B', 'A'): ['A1', 'B1', 'A2'],
                ('A', 'B', 'C'): ['A1', 'B1', 'C2'],
                ('C', 'B', 'A'): ['C1', 'B1', 'A2'],
                ('C', 'B', 'C'): ['C1', 'B1', 'C2']
                },
        'H2O': {('W', ): ['W1'],
                ('Z', ): ['Z1']
                }
    }


# First set correct type
    last_chain_idx = 0
    chain_id = 1
    old2new = {}
    atidx = 1
    new_atoms = {}
    conf_new_atoms = {}
    for at_id, sp in enumerate(species, 1):
        if at_id not in top.atoms:
            continue
        old2new[at_id] = atidx
        at_data = copy.copy(top.atoms[at_id])
        new_atoms[atidx] = at_data
        at_data.atom_type = species2typename[sp]
        at_data.atom_id = atidx
        if top.atoms[at_id].chain_idx != last_chain_idx:
            last_chain_idx = top.atoms[at_id].chain_idx
            at_data.chain_idx = chain_id
            chain_id += 1
        at_data.chain_name = chain_names[sp]
        conf_new_atoms[atidx] = conf.atoms[at_id]._replace(
            chain_name=chain_names[sp], chain_idx=chain_id, atom_id=atidx)
        atidx += 1

    atom_list = [new_atoms[x] for x in sorted(new_atoms)]

# Set names
    at_id = 0
    total_num = len(atom_list)
    while at_id < total_num:
        at_data = atom_list[at_id]
        name_seq = names[at_data.chain_name]
        window_size = len(name_seq.keys()[0])
        at_type_seq = tuple(x.atom_type for x in atom_list[at_id:at_id+window_size])
        for i, x in enumerate(atom_list[at_id:at_id+window_size]):
            x.name = name_seq[at_type_seq][i]
            new_atoms[x.atom_id].atom_name = x.name
            conf_new_atoms[x.atom_id] = conf_new_atoms[x.atom_id]._replace(name=x.name)
        at_id += window_size

    top.atoms = new_atoms
    conf.atoms = conf_new_atoms

    # Replace atom name C to Q (keep the type) this is because for backmapping all atoms has to be
    # unique
    for at_data in top.atoms.values():
        if at_data.name.startswith('C'):
            at_data.name = at_data.name.replace('C', 'Q')

    for at_id, at_data in conf.atoms.items():
        if at_data.name.startswith('C'):
            conf.atoms[at_id] = at_data._replace(name=at_data.name.replace('C', 'Q'))

    top.write(args.out_top, force=True)
    conf.write(args.out_conf, force=True)
from md_libs import files_io
import sys
import networkx as nx

cg_top = files_io.GROMACSTopologyFile(sys.argv[1])
at_top = files_io.GROMACSTopologyFile(sys.argv[2])
cg_top.read()
at_top.read()

g = nx.Graph()
for b1, b2 in cg_top.bonds:
    g.add_edge(b1, b2)

cg_degrees = g.degree()

new_res_names = {}
for at_id in cg_top.atoms:
    at_data = cg_top.atoms[at_id]
    if at_id in cg_degrees:
        if at_data.chain_name == 'DIO':
            if cg_degrees[at_id] == 1:
                new_res_names[at_data.chain_idx] = 'EI1'
            elif cg_degrees[at_id] == 2:
                new_res_names[at_data.chain_idx] = 'EI2'

ter_atoms = range(1001, 4000, 3)
for t in ter_atoms:
    ts = t, t + 1, t + 2
    ts_names = tuple(map(lambda x: x.name, map(cg_top.atoms.get, ts)))
    seq2name = {
        ('Q1', 'B1', 'Q2'): 'TE2',
Exemple #7
0
    ('PA', 'PL', 'RB', 'PB'): 'N1L2',
    ('PA', 'PL', 'RB', 'RB'): 'N1D',  # [3,5,7,7]
    ('RA', 'PL', 'PB', 'PB'): 'N2T',  # [6,5,4,4]
    ('RA', 'PL', 'RB', 'PB'): 'N2L1',  # [6,5,4,7] or [6,5,7,4]
    ('RA', 'PL', 'PB', 'RB'): 'N2L2',  # [6,5,4,7] or [6,5,7,4]
    ('RA', 'PL', 'RB', 'RB'): 'N2D'  # [6,5,7,7]
}

window_size = [len(x) for x in res_type2name]
if len(window_size) != window_size.count(window_size[0]):
    raise RuntimeError('Wrong res_type2name, window size has to be the same')
print('Window size: {}'.format(window_size))
window_size = window_size[0]

args = parser.parse_args()

in_top = files_io.GROMACSTopologyFile(args.in_top)
in_top.read()

at_ids = sorted(in_top.atoms.keys())

for i in range(0, len(at_ids), window_size):
    chunk_at_ids = at_ids[i:i+window_size]
    chunk_types = tuple(in_top.atoms[x].atom_type for x in chunk_at_ids)
    new_res_name = res_type2name[chunk_types]
    print((chunk_types, new_res_name))
    for at_id in chunk_at_ids:
        in_top.atoms[at_id].chain_name = new_res_name

in_top.write(args.out_top)