Ejemplo n.º 1
0
 def test_tetra(self):
     molecule = Molecule.from_file("input/tetra.xyz")
     psf = PSFFile()
     psf.add_molecule(molecule)
     self.assert_(psf.bonds.shape[0] == 4)
     self.assert_(psf.bends.shape[0] == 6)
     psf.write_to_file("output/tetra.psf")
Ejemplo n.º 2
0
    def __call__(self, f, universe, folder, nodes=None):
        atom_counter = 0
        if nodes is None:
            nodes = [universe]

        graph = create_molecular_graph([universe])
        names = [atom.name for atom in graph.molecule.atoms]
        charges = [atom.extra.get("charge", 0.0) for atom in graph.molecule.atoms]
        psf_file = PSFFile()
        psf_file.add_molecular_graph(graph, atom_types=names, charges=charges)
        psf_file.dump(f)
Ejemplo n.º 3
0
 def test_improper(self):
     molecule = Molecule.from_file("input/formol.xyz")
     psf = PSFFile()
     psf.add_molecule(molecule)
     self.assertEqual(psf.impropers.shape, (3,4))
     test_block = set([(row[0], row[1]) for row in psf.impropers])
     self.assert_((0,1) in test_block)
     self.assert_((0,2) in test_block)
     self.assert_((0,3) in test_block)
     psf.write_to_file("output/tmp_impropers.psf")
     psf2 = PSFFile("output/tmp_impropers.psf")
     self.assertArraysEqual(psf.impropers, psf2.impropers)
Ejemplo n.º 4
0
 def test_many_separate(self):
     psf = PSFFile()
     molecule = XYZFile("input/ethene.xyz").get_molecule()
     psf.add_molecule(molecule)
     psf.add_molecule(molecule)
     molecule = XYZFile("input/tea.xyz").get_molecule()
     psf.add_molecule(molecule)
     psf.write_to_file("output/many_separate.psf")
Ejemplo n.º 5
0
 def test_many_separate(self):
     psf = PSFFile()
     molecule = Molecule.from_file("input/ethene.xyz")
     psf.add_molecule(molecule)
     psf.add_molecule(molecule)
     molecule = Molecule.from_file("input/tea.xyz")
     psf.add_molecule(molecule)
     psf.write_to_file("output/many_separate.psf")
Ejemplo n.º 6
0
 def test_tetra(self):
     molecule = XYZFile("input/tetra.xyz").get_molecule()
     psf = PSFFile()
     psf.add_molecule(molecule)
     self.assert_(psf.bonds.shape[0] == 4)
     self.assert_(psf.bends.shape[0] == 6)
     psf.write_to_file("output/tetra.psf")
Ejemplo n.º 7
0
 def _check_topology(self):
     '''
        Check wether all topology information (bonds, bends, dihedrals,
        out-of-plane patterns and neighborlist) is present and complete if
        necessary.
     '''
     assert self.numbers is not None
     if self.bonds is None:
         molecule = Molecule(self.numbers, coordinates=self.ref.coords)
         graph = MolecularGraph.from_geometry(molecule)
         psf = PSFFile()
         psf.add_molecule(molecule)
         self.bonds = np.array(psf.bonds)
         self.bends = np.array(psf.bends)
         self.diheds = np.array(psf.dihedrals)
         self.opdists = find_opdist_patterns(graph)
         self.nlist = graph.neighbors
     else:
         graph = MolecularGraph(self.bonds, self.numbers)
         psf = PSFFile()
         psf.add_molecular_graph(graph)
         if self.bends is None:
             self.bends = np.array(psf.bends)
         if self.diheds is None:
             self.diheds = np.array(psf.dihedrals)
         if self.opdists is None:
             self.opdists = find_opdist_patterns(graph)
         if self.nlist is None:
             self.nlist = graph.neighbors
Ejemplo n.º 8
0
 def test_load(self):
     psf = PSFFile("input/thf.psf")
     self.assert_(psf.bonds.shape[0] == 832)
     self.assert_(psf.bends.shape[0] == 1600)
     self.assert_(psf.dihedrals.shape[0] == 2112)
     g = psf.get_graph()
Ejemplo n.º 9
0
CC30A = CritAnd(HasAtomNumber(6), HasNeighborNumbers(6,6,6,6))
CC31A = CritAnd(HasAtomNumber(6), HasNeighborNumbers(6,6,6,1))
CC32A = CritAnd(HasAtomNumber(6), HasNeighborNumbers(6,6,1,1))
CC33A = CritAnd(HasAtomNumber(6), HasNeighborNumbers(6,1,1,1))

atom_filters = {
    "CC30A": CC30A,
    "CC31A": CC31A,
    "CC32A": CC32A,
    "CC33A": CC33A,
    "HCA1": CritAnd(HasAtomNumber(1), HasNeighbors(CC31A)),
    "HCA2": CritAnd(HasAtomNumber(1), HasNeighbors(CC32A)),
    "HCA3": CritAnd(HasAtomNumber(1), HasNeighbors(CC33A)),
}

def get_atom_type(index, graph):
    for atom_type, atom_filter in atom_filters.iteritems():
        if atom_filter(index, graph):
            return atom_type
    raise ValueError("Unrecognized atom (index %i)." % index)

args = sys.argv[1:]

molecule = XYZFile(args[0]).get_molecule()
graph = MolecularGraph.from_geometry(molecule)
atom_types = [get_atom_type(index, graph) for index in xrange(molecule.size)]

psf = PSFFile()
psf.add_molecular_graph(graph, atom_types=atom_types)
psf.write_to_file(args[0].replace(".xyz", ".psf"))
Ejemplo n.º 10
0
 def test_dump(self):
     m = XYZFile("input/thf.xyz").get_molecule()
     psf = PSFFile()
     psf.add_molecule(m)
     psf.write_to_file("output/thf.psf")
Ejemplo n.º 11
0
 def test_load_vmd(self):
     psf = PSFFile("input/pentapeptide.psf")
     self.assert_(psf.bonds.shape[0] == 44)
     self.assert_(psf.bends.shape[0] == 75)
     self.assert_(psf.dihedrals.shape[0] == 98)
     g = psf.get_graph()
Ejemplo n.º 12
0
 def test_dump(self):
     m = Molecule.from_file("input/thf.xyz")
     psf = PSFFile()
     psf.add_molecule(m)
     psf.write_to_file("output/thf.psf")
Ejemplo n.º 13
0
 def test_load(self):
     psf = PSFFile("input/thf.psf")
     self.assert_(psf.bonds.shape[0] == 832)
     self.assert_(psf.bends.shape[0] == 1600)
     self.assert_(psf.dihedrals.shape[0] == 2112)
     g = psf.get_graph()
Ejemplo n.º 14
0
 def test_dump(self):
     m = XYZFile("input/thf.xyz").get_molecule()
     psf = PSFFile()
     psf.add_molecule(m)
     psf.write_to_file("output/thf.psf")
Ejemplo n.º 15
0
CC30A = CritAnd(HasAtomNumber(6), HasNeighborNumbers(6,6,6,6))
CC31A = CritAnd(HasAtomNumber(6), HasNeighborNumbers(6,6,6,1))
CC32A = CritAnd(HasAtomNumber(6), HasNeighborNumbers(6,6,1,1))
CC33A = CritAnd(HasAtomNumber(6), HasNeighborNumbers(6,1,1,1))

atom_filters = {
    "CC30A": CC30A,
    "CC31A": CC31A,
    "CC32A": CC32A,
    "CC33A": CC33A,
    "HCA1": CritAnd(HasAtomNumber(1), HasNeighbors(CC31A)),
    "HCA2": CritAnd(HasAtomNumber(1), HasNeighbors(CC32A)),
    "HCA3": CritAnd(HasAtomNumber(1), HasNeighbors(CC33A)),
}

def get_atom_type(index, graph):
    for atom_type, atom_filter in atom_filters.items():
        if atom_filter(index, graph):
            return atom_type
    raise ValueError("Unrecognized atom (index %i)." % index)

args = sys.argv[1:]

molecule = XYZFile(args[0]).get_molecule()
graph = MolecularGraph.from_geometry(molecule)
atom_types = [get_atom_type(index, graph) for index in range(molecule.size)]

psf = PSFFile()
psf.add_molecular_graph(graph, atom_types=atom_types)
psf.write_to_file(args[0].replace(".xyz", ".psf"))
Ejemplo n.º 16
0
 def test_load_vmd(self):
     psf = PSFFile("input/pentapeptide.psf")
     self.assert_(psf.bonds.shape[0] == 44)
     self.assert_(psf.bends.shape[0] == 75)
     self.assert_(psf.dihedrals.shape[0] == 98)
     g = psf.get_graph()
Ejemplo n.º 17
0
    def from_files(cls, fns, ei_path=None, vdw_path=None, bondsin=None):
    # original
    #def from_files(cls, fns, ei_path=None, vdw_path=None):
    #SHLL end
        '''
           A method to construct a System instance from input files. If
           the input files do not contain the topology, it is estimated
           from the geometry.

           **Arguments:**

           fns
                A list of file names. Files further on in the list will
                overwrite earlier files if there is overlap. txt files
                can only be used in hipart format to define charges. HDF5
                files can only be used in Horton format to define charges.
                The set of charges that will be extracted from the HDF5
                file is dependant on the charge scheme defined in the
                kwargs.

           **Optional Arguments:**

           ei_path
                A string defining the path in the HDF5 file which contains a
                dataset `EI_PATH/charges` (and `EI_PATH/radii` in case of
                Gaussian charges) from which the atomic charges will be
                extracted.

           vdw_path
                A string defining the path in the HDF5 file which contains 2
                datasets, `VDW_PATH/epsilons` and `VDW_PATH/sigmas` from which
                the atomic vdW parameters will be extracted.
        '''
        #initialise
        numbers = None
        charges = None
        radii = None
        epsilons = None
        sigmas = None
        ffatypes = None
        #SHLL 1512
        #-- Make it possible to manually define atom connectivity while reading others from file
        bonds = bondsin
        # original
        #bonds = None
        #SHLL end
        bends = None
        diheds = None
        opdists = None
        nlist = None
        ref = ReferenceData()
        #Read all input files
        for fn in fns:
            extension = fn.split('.')[-1]
            if extension in ['chk', 'mfs']:
                sample = load_chk(fn)
                for key, value in sample.iteritems():
                    if key in ['numbers']:
                        numbers = value
                    elif key in ['charges', 'ac', 'aq']:
                        charges = value
                    elif key in ['radii']:
                        radii = value
                    elif key in ['epsilons']:
                        epsilons = value
                    elif key in ['sigmas']:
                        sigmas = value
                    elif key in ['ffatypes', 'atypes']:
                        ffatypes = value
                    elif key in ['bonds']:
                        bonds = value
                    elif key in ['bends', 'angles']:
                        bends = value
                    elif key in ['diheds', 'dihedrals']:
                        diheds = value
                    elif key in ['opdists']:
                        opdists = value
                    elif key in ['coords', 'coordinates', 'pos']:
                        ref.update(coords=value.reshape([-1, 3]))
                    elif key in ['gradient', 'grad', 'gpos', 'forces']:
                        ref.update(grad=value.reshape([-1, 3]))
                    elif key in ['hessian', 'hess']:
                        natoms = int(np.sqrt(value.size/9))
                        ref.update(hess=value.reshape([natoms, 3, natoms, 3]))
            elif extension in ['fchk']:
                fchk = FCHKFile(fn)
                numbers = fchk.fields.get('Atomic numbers')
                ref.update(coords=fchk.fields.get('Current cartesian coordinates').reshape([len(numbers), 3]))
                ref.update(grad=fchk.fields.get('Cartesian Gradient').reshape([len(numbers), 3]))
                ref.update(hess=fchk.get_hessian().reshape([len(numbers), 3, len(numbers), 3]))
            elif extension in ['psf']:
                psf = PSFFile(fn)
                numbers = np.array(psf.numbers)
                ffatypes = np.array(psf.atom_types)
                charges = np.array(psf.charges)
                bonds = np.array(psf.bonds)
                bends = np.array(psf.bends)
                diheds = np.array(psf.dihedrals)
                nlist = psf.get_molecular_graph().neighbors
            elif extension in ['h5']:
                import h5py
                f = h5py.File(fn, 'r')
                if ei_path is None and vdw_path is None:
                    print '\nWARNING: a HDF5 file was given but both ei_path and'  +\
                          'vdw_path are None, HDF5 file is ignored.\n'
                if ei_path is not None:
                    charges = f['%s/charges' % ei_path][:]
                    if '%s/radii' %ei_path in f:
                        radii = f['%s/radii' %ei_path][:]
                if vdw_path is not None:
                    epsilons = f['%s/epsilons' % vdw_path][:]
                    sigmas = f['%s/sigmas' % vdw_path][:]
            else:
                raise IOError('Unsupported file format for %s' %fn)
        return cls(numbers, ref, ffatypes=ffatypes, charges=charges,
                   radii=radii, epsilons=epsilons, sigmas=sigmas, bonds=bonds,
                   bends=bends, diheds=diheds, opdists=opdists, nlist=nlist)