new_structure_api Function

public function new_structure_api(verror, natoms, numbers, positions, c_charge, c_lattice, c_periodic) result(vmol) bind(C, name=namespace//"new_structure")

Create new molecular structure data (quantities in Bohr)

Arguments

Type IntentOptional Attributes Name
type(c_ptr), value :: verror
integer(kind=c_int), intent(in), value :: natoms
integer(kind=c_int), intent(in) :: numbers(natoms)
real(kind=c_double), intent(in) :: positions(3,natoms)
real(kind=c_double), intent(in), optional :: c_charge
real(kind=c_double), intent(in), optional :: c_lattice(3,3)
logical(kind=c_bool), intent(in), optional :: c_periodic(3)

Return Value type(c_ptr)


Source Code

function new_structure_api(verror, natoms, numbers, positions, c_charge, &
      & c_lattice, c_periodic) result(vmol) &
      & bind(C, name=namespace//"new_structure")
   !DEC$ ATTRIBUTES DLLEXPORT :: new_structure_api
   type(c_ptr), value :: verror
   type(vp_error), pointer :: error
   integer(c_int), value, intent(in) :: natoms
   integer(c_int), intent(in) :: numbers(natoms)
   real(c_double), intent(in) :: positions(3, natoms)
   real(c_double), intent(in), optional :: c_charge
   real(wp), allocatable :: charge
   real(c_double), intent(in), optional :: c_lattice(3, 3)
   real(wp), allocatable :: lattice(:, :)
   logical(c_bool), intent(in), optional :: c_periodic(3)
   logical, allocatable :: periodic(:)
   type(vp_structure), pointer :: mol
   type(c_ptr) :: vmol

   if (debug) print'("[Info]",1x, a)', "new_structure"

   vmol = c_null_ptr

   if (.not.c_associated(verror)) return
   call c_f_pointer(verror, error)

   if (present(c_lattice)) then
      allocate(lattice(3, 3))
      lattice(:, :) = c_lattice
   end if
   if (present(c_periodic)) then
      allocate(periodic(3))
      periodic(:) = c_periodic
   end if
   if (present(c_charge)) then
      charge = c_charge
   end if

   allocate(mol)
   call new(mol%ptr, numbers, positions, lattice=lattice, periodic=periodic, &
      charge=charge)
   vmol = c_loc(mol)

   call wrap_to_central_cell(mol%ptr%xyz, mol%ptr%lattice, mol%ptr%periodic)

   call verify_structure(error%ptr, mol%ptr)

end function new_structure_api