Exemplo n.º 1
0
 def get_nelec(self, geom, multiplicity):
     atoms = manage_xyz.get_atoms(geom)
     elements = [ELEMENT_TABLE.from_symbol(atom) for atom in atoms]
     atomic_num = [ele.atomic_num for ele in elements]
     self.n_electrons = sum(atomic_num) - self.charge
     if self.n_electrons < 0:
         raise ValueError("Molecule has fewer than 0 electrons!!!")
     self.check_multiplicity(multiplicity)
     return
Exemplo n.º 2
0
    def __init__(self, options, **kwargs):

        self.Data = options

        # => Read in the coordinates <= #
        # important first try to read in geom

        t0 = time()
        if self.Data['geom'] is not None:
            print(" getting cartesian coordinates from geom")
            atoms = manage_xyz.get_atoms(self.Data['geom'])
            xyz = manage_xyz.xyz_to_np(self.Data['geom'])
        elif self.Data['fnm'] is not None:
            print(" reading cartesian coordinates from file")
            if self.Data['ftype'] is None:
                self.Data['ftype'] = os.path.splitext(self.Data['fnm'])[1][1:]
            if not os.path.exists(self.Data['fnm']):
                #logger.error('Tried to create Molecule object from a file that does not exist: %s\n' % self.Data['fnm'])
                raise IOError
            geom = manage_xyz.read_xyz(self.Data['fnm'], scale=1.)
            xyz = manage_xyz.xyz_to_np(geom)
            atoms = manage_xyz.get_atoms(geom)

        else:
            raise RuntimeError

        t1 = time()
        print(" Time to get coords= %.3f" % (t1 - t0))
        #resid=[]
        #for a in ob.OBMolAtomIter(mol.OBMol):
        #    res = a.GetResidue()
        #    resid.append(res.GetName())
        #self.resid = resid

        # Perform all the sanity checks and cache some useful attributes

        # TODO make PES property
        self.PES = type(self.Data['PES']).create_pes_from(
            PES=self.Data['PES'],
            options={'node_id': self.Data['node_id']},
            copy_wavefunction=self.Data['copy_wavefunction'])
        if not hasattr(atoms, "__getitem__"):
            raise TypeError("atoms must be a sequence of atomic symbols")

        for a in atoms:
            if not isinstance(a, str):
                raise TypeError("atom symbols must be strings")

        if type(xyz) is not np.ndarray:
            raise TypeError("xyz must be a numpy ndarray")
        if xyz.shape != (len(atoms), 3):
            raise ValueError("xyz must have shape natoms x 3")
        self.Data['xyz'] = xyz.copy()

        # create a dictionary from atoms
        # atoms contain info you need to know about the atoms
        self.atoms = [ELEMENT_TABLE.from_symbol(atom) for atom in atoms]

        tx = time()
        print(" Time to create PES,elements %.3f" % (tx - t1))
        t1 = tx

        if not isinstance(self.Data['comment'], str):
            raise TypeError("comment for a Molecule must be a string")

        # Create the coordinate system
        if self.Data['coord_obj'] is not None:
            print(" getting coord_object from options")
            self.coord_obj = self.Data['coord_obj']
        else:
            print(
                " Disabling this feature, Molecule cannot create coordinate system"
            )
            raise NotImplementedError
        #elif self.Data['coordinate_type'] == "Cartesian":
        #    self.coord_obj = CartesianCoordinates.from_options(xyz=self.xyz,atoms=self.atoms)
        #elif self.Data['coordinate_type'] == "DLC":
        #    print(" building coordinate object")
        #    self.coord_obj = DelocalizedInternalCoordinates.from_options(xyz=self.xyz,atoms=self.atoms,connect=True,extra_kwargs =self.Data['top_settings'])
        #elif self.Data['coordinate_type'] == "HDLC":
        #    self.coord_obj = DelocalizedInternalCoordinates.from_options(xyz=self.xyz,atoms=self.atoms,addcart=True,extra_kwargs =self.Data['top_settings'])
        #elif self.Data['coordinate_type'] == "TRIC":
        #    self.coord_obj = DelocalizedInternalCoordinates.from_options(xyz=self.xyz,atoms=self.atoms,addtr=True,extra_kwargs =self.Data['top_settings'])
        self.Data['coord_obj'] = self.coord_obj

        t2 = time()
        print(" Time  to build coordinate system= %.3f" % (t2 - t1))

        #TODO
        self.gradrms = 0.
        self.isTSnode = False
        self.bdist = 0.
        self.newHess = 5

        if self.Data['Hessian'] is None and self.Data['Form_Hessian']:
            if self.Data['Primitive_Hessian'] is None and type(
                    self.coord_obj) is not CartesianCoordinates:
                self.form_Primitive_Hessian()
            t3 = time()
            print(" Time to build Prim Hessian %.3f" % (t3 - t2))
            if self.Data['Primitive_Hessian'] is not None:
                print(" forming Hessian in basis")
                self.form_Hessian_in_basis()
            else:
                self.form_Hessian()

        #logger.info("Molecule %s constructed.", repr(self))
        #logger.debug("Molecule %s constructed.", repr(self))
        print(" molecule constructed")
Exemplo n.º 3
0
    def __init__(
        self,
        options,
    ):
        """ Constructor """

        self.options = options

        # properties
        self.Energy = namedtuple('Energy', 'value unit')
        self.Gradient = namedtuple('Gradient', 'value unit')
        self.Coupling = namedtuple('Coupling', 'value unit')
        self._Energies = {}
        self._Gradients = {}
        self._Couplings = {}

        # count number of states
        singlets = self.search_tuple(self.states, 1)
        doublets = self.search_tuple(self.states, 2)
        triplets = self.search_tuple(self.states, 3)
        quartets = self.search_tuple(self.states, 4)
        quintets = self.search_tuple(self.states, 5)

        #TODO do this for all states, since it catches if states are put in lazy e.g [(1,1)]
        if singlets:
            len_singlets = max(singlets, key=lambda x: x[1])[1] + 1
        else:
            len_singlets = 0
        len_doublets = len(doublets)
        len_triplets = len(triplets)
        len_quartets = len(quartets)
        len_quintets = len(quintets)

        # DO this before fixing states if put in lazy
        if self.options['gradient_states'] == None and self.calc_grad:
            print(" Assuming gradient states are ", self.states)
            self.options['gradient_states'] = self.options['states']

        if len(
                self.states
        ) < len_singlets + len_doublets + len_triplets + len_quartets + len_quintets:
            print('fixing states to be proper length')
            tmp = []
            # TODO put in rest of fixed states
            for i in range(len_singlets):
                tmp.append((1, i))
            for i in range(len_triplets):
                tmp.append((3, i))
            self.states = tmp
            print(' New states ', self.states)

        self.geom = self.options['geom']
        if self.geom is not None:
            print(" initializing LOT from geom")
        elif self.options['fnm'] is not None:
            print(" initializing LOT from file")
            if not os.path.exists(self.options['fnm']):
                logger.error(
                    'Tried to create LOT object from a file that does not exist: %s\n'
                    % self.options['fnm'])
                raise IOError
            self.geom = manage_xyz.read_xyz(self.options['fnm'], scale=1.)
        else:
            raise RuntimeError("Need to initialize LOT object")

        # Cache some useful atributes - other useful attributes are properties
        self.currentCoords = manage_xyz.xyz_to_np(self.geom)
        self.atoms = manage_xyz.get_atoms(self.geom)
        self.ID = self.options['ID']
        self.nproc = self.options['nproc']
        self.charge = self.options['charge']
        self.node_id = self.options['node_id']
        self.lot_inp_file = self.options['lot_inp_file']

        # Bools for running
        self.hasRanForCurrentCoords = False
        self.has_nelectrons = False

        # Read file options if they exist and not already set
        if self.file_options is None:
            self.file_options = File_Options(self.lot_inp_file)

        #package  specific implementation
        #TODO MOVE to specific package !!!
        # tc cloud
        self.options['job_data']['orbfile'] = self.options['job_data'].get(
            'orbfile', '')
        # pytc? TODO
        self.options['job_data']['lot'] = self.options['job_data'].get(
            'lot', None)

        print(" making folder scratch/{:03}/{}".format(self.ID, self.node_id))
        os.system('mkdir -p scratch/{:03}/{}'.format(self.ID, self.node_id))
Exemplo n.º 4
0
            # self.nodes[-1].energy = self.nodes[0].energy
            # self.nodes[-1].gradrms = 0.


if __name__ == '__main__':
    from level_of_theories.dummy_lot import Dummy
    from potential_energy_surfaces.pes import PES
    from coordinate_systems.delocalized_coordinates import DelocalizedInternalCoordinates, PrimitiveInternalCoordinates, Topology
    from optimizers import eigenvector_follow

    geoms = manage_xyz.read_molden_geoms(
        '../growing_string_methods/opt_converged_000.xyz')
    lot = Dummy.from_options(geom=geoms[0])

    pes = PES.from_options(lot=lot, ad_idx=0, multiplicity=1)
    atom_symbols = manage_xyz.get_atoms(geoms[0])

    ELEMENT_TABLE = elements.ElementData()
    atoms = [ELEMENT_TABLE.from_symbol(atom) for atom in atom_symbols]
    xyz1 = manage_xyz.xyz_to_np(geoms[0])
    xyz2 = manage_xyz.xyz_to_np(geoms[-1])

    top1 = Topology.build_topology(
        xyz1,
        atoms,
    )

    # find union bonds
    xyz2 = manage_xyz.xyz_to_np(geoms[-1])
    top2 = Topology.build_topology(
        xyz2,