% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/calculate_properties.R
\name{filter_ghost_distances}
\alias{filter_ghost_distances}
\title{Filter Ghost Distances Using Atomic Radii}
\usage{
filter_ghost_distances(
  distances,
  atomic_coordinates,
  margin = 0.1,
  radii_type = "covalent"
)
}
\arguments{
\item{distances}{A \code{data.table} of interatomic distances, typically from
\code{calculate_distances}. Must contain \code{Atom1}, \code{Atom2}, and \code{Distance}.}

\item{atomic_coordinates}{A \code{data.table} of asymmetric atoms from
\code{extract_atomic_coordinates}. Used to link atom labels to element types.}

\item{margin}{A numeric value (default 0.1) specifying the tolerance. A
distance \code{d} between atoms with radii \code{r1} and \code{r2} is kept if
\verb{(r1+r2)*(1-margin) <= d <= (r1+r2)*(1+margin)}.}

\item{radii_type}{A character string specifying the type of radius to use for
the calculation (e.g., \code{"covalent"}, \code{"ionic"}). This value must correspond
to an entry in the \code{Type} column of the active radii table. Defaults to \code{"covalent"}.
The radii table can be customized for the session using \code{set_radii_data()}.}
}
\value{
A list containing two \code{data.table}s:
\item{kept}{The distances considered physically plausible.}
\item{removed}{The "ghost" distances that were filtered out, with columns
explaining the reason for removal.}
}
\description{
Cleans a distance table by removing physically implausible distances.
It uses a table of atomic radii to establish a plausible bond length
range for each atom pair. Any calculated distance falling outside this range
(defined by a \code{margin}) is considered a "ghost" distance and is removed. This
is particularly useful for cleaning data from disordered crystal structures.
}
\examples{
# Create minimal dummy data for demonstration
distances <- data.table::data.table(
  Atom1 = c("Si1_1_0_0", "O1_1_0_0"),
  Atom2 = c("O1_1_0_0", "Si1_1_0_0"),
  Distance = c(1.6, 0.5) # 0.5 is implausibly short
)

atomic_coords <- data.table::data.table(
  Label = c("Si1", "O1")
)

# Run the filter
result <- filter_ghost_distances(distances, atomic_coords, margin = 0.1)

print(result$kept)
print(result$removed)
}
\seealso{
Other post-processing: 
\code{\link{calculate_weighted_average_network_distance}()},
\code{\link{set_radii_data}()}
}
\concept{post-processing}
