예제 #1
0
def test_guess_bonds():
    u = mda.Universe(two_water_gro)
    bonds = guessers.guess_bonds(u.atoms, u.atoms.positions, u.dimensions)
    assert_equal(bonds, ((0, 1),
                         (0, 2),
                         (3, 4),
                         (3, 5)))
예제 #2
0
def test_guess_bonds_peptide():
    u = mda.Universe(datafiles.PSF_NAMD, datafiles.PDB_NAMD)
    u.atoms.types = guessers.guess_types(u.atoms.names)
    bonds = bond_sort(guessers.guess_bonds(u.atoms, u.atoms.positions))
    assert_equal(np.sort(u.bonds.indices, axis=0), np.sort(bonds, axis=0))
예제 #3
0
def test_guess_bonds_water():
    u = mda.Universe(datafiles.two_water_gro)
    bonds = bond_sort(
        guessers.guess_bonds(u.atoms, u.atoms.positions, u.dimensions))
    assert_equal(bonds, ((0, 1), (0, 2), (3, 4), (3, 5)))
예제 #4
0
def test_guess_bonds_Error():
    u = make_Universe(trajectory=True)
    with pytest.raises(ValueError):
        guessers.guess_bonds(u.atoms[:4], u.atoms.positions[:5])
예제 #5
0
 def time_guessbonds(self, num_atoms):
     """Benchmark for guessing bonds"""
     guessers.guess_bonds(self.ag, self.ag.positions,
                          box=self.ag.dimensions,
                          vdwradii=self.vdwradii)
예제 #6
0
def test_guess_bonds_adk():
    u = mda.Universe(datafiles.PSF, datafiles.DCD)
    u.atoms.types = guessers.guess_types(u.atoms.names)
    bonds = guessers.guess_bonds(u.atoms, u.atoms.positions)
    assert_equal(np.sort(u.bonds.indices, axis=0), np.sort(bonds, axis=0))
def test_guess_bonds():
    u = mda.Universe(two_water_gro)
    bonds = guessers.guess_bonds(u.atoms, u.atoms.positions, u.dimensions)
    assert_equal(bonds, ((0, 1), (0, 2), (3, 4), (3, 5)))
예제 #8
0
def create_full_trajectory(*, nCycles, path, filetype, output):
    ## some setup
    getFilenameTop, getFilenameTrj = helper.make_get_filename(FILETYPE=filetype, PATH=path)
    getReactiveAtomIndices = helper.make_get_reactive_atoms(FILETYPE=filetype, PATH=path)
    
    frameCounter = 0

    write_frame = helper.make_get_write(filename=output)
    FILE = open(output, 'w')

    ## get initial data from cycle 0
    universe = mda.Universe( getFilenameTop(0), getFilenameTrj(0) )
    atomNames = universe.atoms.names
    resNames = universe.atoms.resnames
    resIDs = universe.atoms.resnums
    atomOrder = universe.atoms.ix
    dt = universe.trajectory.dt
    ## important: sort topology such that resnames are in alphabetical order (because rs@md does this, too...)
    # first: sort resnames alphabetically and adapt resIDs, atomNames
    sortedIndices = resNames.argsort(kind='stable')
    atomNames = atomNames[sortedIndices]
    resNames = resNames[sortedIndices]
    resIDs = resIDs[sortedIndices]
    atomOrderRearrangedAlphabetically = atomOrder[sortedIndices]
    # second: renumber residues
    counterResID = 1
    newResIDs = resIDs.copy()
    for ix in range(len(resIDs)-1):
        newResIDs[ix] = counterResID
        if resIDs[ix] != resIDs[ix+1]:
            counterResID += 1
    resIDs = newResIDs

	## create initial coordination file where all residues have been unwrapped and save it to file
    #for res in universe.atoms.residues:
    #    ag = res.atoms
    #    transform = mdatrans.unwrap(ag)
    #    universe.trajectory.add_transformations(transform)
    if not hasattr(universe, 'bonds'):
        guessed_bonds = mdaguess.guess_bonds(universe.atoms, universe.atoms.positions, universe.trajectory[0].dimensions)
        universe.add_TopologyAttr('bonds', guessed_bonds)
    transform = mdatrans.unwrap(universe.atoms)
    universe.trajectory.add_transformations(transform)
    outputinitial = 'initial' + '.' + output.split('.')[-1]
    initialFile = open(outputinitial, 'w')
    box = universe.trajectory[0].dimensions
    positions = universe.atoms.positions
    sortedPositions = positions[sortedIndices]
    write_frame(filestream=initialFile, title=f'rs@md t={0:9.2f} step= {0}', resnames=resNames, resnums=resIDs, names=atomNames, positions=sortedPositions, box=box)
    initialFile.close()
    print(f'-> initial frame has been written to {outputinitial}')

    ## write trajectory to file frame by frame
    for ts in universe.trajectory:  
        positions = universe.atoms.positions
        box = ts.dimensions
        ## sort positions before writing them
        sortedPositions = positions[sortedIndices]
        write_frame(filestream=FILE, title=f'rs@md t={frameCounter*dt:9.2f} step=  {frameCounter}', resnames=resNames, resnums=resIDs, names=atomNames, positions=sortedPositions, box=box)
        frameCounter += 1

    ## loop through all files and record remaining data
    firstReactiveCycle = True
    for cycle in np.arange(1, nCycles+1):
        topfile = getFilenameTop(cycle)
        trjfile = getFilenameTrj(cycle)

        if os.path.isfile( trjfile ):
            ## get reaction infos
            reactantsIx, productsIx = getReactiveAtomIndices(cycle)
            
            ## attention if firstReactiveCycle: their might have been a change in atomOrder between cycles 0 -> cycle
            ## due to reordering molecules in alphabetical order
            ## need to account for that by translating reactantsIx accordingly
            if firstReactiveCycle:
                reactantsIx = np.array( [np.argwhere(atomOrderRearrangedAlphabetically == rix)[0,0] for rix in reactantsIx] )
                firstReactiveCycle = False                

            ## important: you need to go through all transitions in an ordered fashion with respect to the product indices 
            ## (from small to larger iy)
            sortedIndices = productsIx.argsort()
            reactantsIx = reactantsIx[sortedIndices]
            productsIx = productsIx[sortedIndices]
            
            ## apply reactions to atomOrder
            ## i.e. change positions of reactants to products

            ## ... first: get entries at reactant positions and remove them from list
            reactantEntries = [ atomOrder[x] for x in reactantsIx ]
            for entry in reactantEntries:
                atomOrder = np.delete(atomOrder, np.argwhere(atomOrder==entry), axis=0)
           
            ## ... second: put entries back at new positions given by product positions
            for iy, entry in zip(productsIx, reactantEntries):
                atomOrder = np.insert(atomOrder, iy, entry, axis=0)

            ## get sorted indices for new atomOrder
            sortedIndices = atomOrder.argsort()

            ## import trajectory: .tpr, .gro/.xtc/...
            universe = mda.Universe(topfile, trjfile)

            ## write trajectory to file frame by frame
            for ts in universe.trajectory[1:]:  
                positions = universe.atoms.positions
                box = ts.dimensions
                
                ## sort positions before writing them
                sortedPositions = positions[sortedIndices]
                write_frame(filestream=FILE, title=f'rs@md t={frameCounter*dt:9.2f} step=  {frameCounter}', resnames=resNames, resnums=resIDs, names=atomNames, positions=sortedPositions, box=box)
                frameCounter += 1

        else:
            continue

    FILE.close()

    print(f'-> a total of {frameCounter} frames have been written to {output}')
예제 #9
0
def test_guess_bonds_Error():
    u = make_Universe(trajectory=True)
    with pytest.raises(ValueError):
        guessers.guess_bonds(u.atoms[:4], u.atoms.positions[:5])